A bunch of changes

This commit is contained in:
Alexander Rosenberg 2022-12-31 18:18:49 -08:00
parent 5d67fcbb0c
commit 271319297d
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730
2 changed files with 22 additions and 16 deletions

View File

@ -33,15 +33,8 @@
:pattern ,pattern_table :pattern ,pattern_table
:callback ,callback }))) :callback ,callback })))
;; Nicer macro for use ;; Nicer macro for use
;; (lambda use! [repo ...] ;; :config acts like use-package's :init and :config options,
;; (local output [ repo ]) ;; taking in the following lisp expressions as its arguments
;; (var last_key nil)
;; (each [_ val (ipairs [...])]
;; (if last_key
;; (do (tset output last_key val)
;; (set last_key nil))
;; (set last_key val)))
;; `(use ,output))
(lambda use! [repo ...] (lambda use! [repo ...]
(local output [ repo ]) (local output [ repo ])
(var last_key nil) (var last_key nil)
@ -64,8 +57,7 @@
(tset output :config config_entries)) (tset output :config config_entries))
`(use ,output)) `(use ,output))
;; Can be passed to :config of `use!' ;; Call a plugin's `setup function'
;; to call a plugin's `setup' function
(lambda setup! [pkg ...] (local output [ ]) (lambda setup! [pkg ...] (local output [ ])
(var last_key nil) (var last_key nil)
(each [_ val (ipairs [...])] (each [_ val (ipairs [...])]
@ -83,9 +75,21 @@
(lambda module-fn! [mod func] (lambda module-fn! [mod func]
`(. (require ,mod) ,func)) `(. (require ,mod) ,func))
;; Basically does what the Emacs function of the same name does.
;; Wraps the code inside with a `winsaveview' and `winrestview'
(lambda save-excursion! [...]
(let [args [...]
len (# args)]
(tset args len `(let [retvar# ,(. args len)]
(vim.fn.winrestview save#)
retvar#))
`(let [save# (vim.fn.winsaveview)]
,(unpack args))))
{: bind! {: bind!
: hook! : hook!
: use! : use!
: setup! : setup!
: module-call! : module-call!
: module-fn!} : module-fn!
: save-excursion!}

View File

@ -1,6 +1,7 @@
;;; init.fnl - primary init file ;;; init.fnl - primary init file
(import-macros {: bind! : module-call! : hook!} :macros) (import-macros {: bind! : module-call! : hook!
: save-excursion! } :macros)
;; Make space leader ;; Make space leader
(set vim.g.mapleader " ") (set vim.g.mapleader " ")
@ -61,8 +62,9 @@
;; Remove trailing whitespace ;; Remove trailing whitespace
(fn remove-trailing-whitespace [] (fn remove-trailing-whitespace []
"Remove trailing whitespace from the whole file." "Remove trailing whitespace from the whole file."
(pcall vim.cmd "%s/ \\+$//") (save-excursion!
(vim.cmd.nohlsearch)) (vim.api.nvim_exec "keepjumps keeppatterns silent! %s/ \\+$//" false)
(vim.api.nvim_exec "keepjumps keeppatterns silent! 0;/^\\%(\\n*.\\)\\@!/,$d_" false)))
(vim.api.nvim_create_user_command :RemoveTrailingWhitespace (vim.api.nvim_create_user_command :RemoveTrailingWhitespace
remove-trailing-whitespace {}) remove-trailing-whitespace {})
(hook! [ :BufWritePre ] "*" remove-trailing-whitespace) (hook! [ :BufWritePre ] "*" remove-trailing-whitespace)