diff options
author | Alex Kost <alezost@gmail.com> | 2015-11-17 22:10:46 +0300 |
---|---|---|
committer | Alex Kost <alezost@gmail.com> | 2016-01-02 17:25:35 +0300 |
commit | 36c00c61fa257f5177ba9bc54a2d57191b70909f (patch) | |
tree | f0f9da8afa5891b08b5a60fc1e6433fcc49c133e /emacs/guix-utils.el | |
parent | 778437ed9f4586370512768f06bfd9c33c3906a2 (diff) | |
download | patches-36c00c61fa257f5177ba9bc54a2d57191b70909f.tar patches-36c00c61fa257f5177ba9bc54a2d57191b70909f.tar.gz |
emacs: Add 'guix-with-indent'.
* emacs/guix-utils.el (guix-with-indent): New macro.
(guix-memoized-font-lock-keywords): Rename to...
(guix-utils-font-lock-keywords): ... this. Add it.
* emacs/guix-info.el (guix-info-insert-entry-default): Use it.
Diffstat (limited to 'emacs/guix-utils.el')
-rw-r--r-- | emacs/guix-utils.el | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/emacs/guix-utils.el b/emacs/guix-utils.el index 5f3f3ecc10..5a0cad4f2a 100644 --- a/emacs/guix-utils.el +++ b/emacs/guix-utils.el @@ -64,6 +64,17 @@ Use `guix-time-format'." "Return one-line string from a multi-line STR." (replace-regexp-in-string "\n" " " str)) +(defmacro guix-with-indent (indent &rest body) + "Evaluate BODY and indent inserted text by INDENT number of spaces." + (declare (indent 1) (debug t)) + (let ((region-beg-var (make-symbol "region-beg")) + (indent-var (make-symbol "indent"))) + `(let ((,region-beg-var (point)) + (,indent-var ,indent)) + ,@body + (unless (zerop ,indent-var) + (indent-rigidly ,region-beg-var (point) ,indent-var))))) + (defun guix-format-insert (val &optional face format) "Convert VAL into a string and insert it at point. If FACE is non-nil, propertize VAL with FACE. @@ -303,9 +314,13 @@ See `defun' for the meaning of arguments." ,(or docstring (format "Memoized version of `%S'." definition)))) -(defvar guix-memoized-font-lock-keywords + +(defvar guix-utils-font-lock-keywords (eval-when-compile - `((,(rx "(" + `((,(rx "(" (group "guix-with-indent") + symbol-end) + . 1) + (,(rx "(" (group "guix-memoized-" (or "defun" "defalias")) symbol-end (zero-or-more blank) @@ -314,7 +329,7 @@ See `defun' for the meaning of arguments." (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))))) -(font-lock-add-keywords 'emacs-lisp-mode guix-memoized-font-lock-keywords) +(font-lock-add-keywords 'emacs-lisp-mode guix-utils-font-lock-keywords) (provide 'guix-utils) |