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
:callback ,callback })))
;; Nicer macro for use
;; (lambda use! [repo ...]
;; (local output [ repo ])
;; (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))
;; :config acts like use-package's :init and :config options,
;; taking in the following lisp expressions as its arguments
(lambda use! [repo ...]
(local output [ repo ])
(var last_key nil)
@ -64,8 +57,7 @@
(tset output :config config_entries))
`(use ,output))
;; Can be passed to :config of `use!'
;; to call a plugin's `setup' function
;; Call a plugin's `setup function'
(lambda setup! [pkg ...] (local output [ ])
(var last_key nil)
(each [_ val (ipairs [...])]
@ -83,9 +75,21 @@
(lambda module-fn! [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!
: hook!
: use!
: setup!
: module-call!
: module-fn!}
: module-fn!
: save-excursion!}

View File

@ -1,6 +1,7 @@
;;; init.fnl - primary init file
(import-macros {: bind! : module-call! : hook!} :macros)
(import-macros {: bind! : module-call! : hook!
: save-excursion! } :macros)
;; Make space leader
(set vim.g.mapleader " ")
@ -61,8 +62,9 @@
;; Remove trailing whitespace
(fn remove-trailing-whitespace []
"Remove trailing whitespace from the whole file."
(pcall vim.cmd "%s/ \\+$//")
(vim.cmd.nohlsearch))
(save-excursion!
(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
remove-trailing-whitespace {})
(hook! [ :BufWritePre ] "*" remove-trailing-whitespace)