[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/38: emacs: Add 'guix-with-indent'.
From: |
Alex Kost |
Subject: |
02/38: emacs: Add 'guix-with-indent'. |
Date: |
Sat, 02 Jan 2016 14:27:16 +0000 |
alezost pushed a commit to branch master
in repository guix.
commit 36c00c61fa257f5177ba9bc54a2d57191b70909f
Author: Alex Kost <address@hidden>
Date: Tue Nov 17 22:10:46 2015 +0300
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.
---
emacs/guix-info.el | 8 +++-----
emacs/guix-utils.el | 21 ++++++++++++++++++---
2 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/emacs/guix-info.el b/emacs/guix-info.el
index 1c7e79b..c9054e1 100644
--- a/emacs/guix-info.el
+++ b/emacs/guix-info.el
@@ -219,13 +219,11 @@ ENTRIES should have a form of `guix-entries'."
"Insert ENTRY of ENTRY-TYPE into the current info buffer.
If INDENT-LEVEL is non-nil, indent displayed information by this
number of `guix-info-indent' spaces."
- (let ((region-beg (point)))
+ (guix-with-indent (* (or indent-level 0)
+ guix-info-indent)
(mapc (lambda (param)
(guix-info-insert-param param entry entry-type))
- (guix-info-get-displayed-params entry-type))
- (when indent-level
- (indent-rigidly region-beg (point)
- (* indent-level guix-info-indent)))))
+ (guix-info-get-displayed-params entry-type))))
(defun guix-info-insert-entry (entry entry-type &optional indent-level)
"Insert ENTRY of ENTRY-TYPE into the current info buffer.
diff --git a/emacs/guix-utils.el b/emacs/guix-utils.el
index 5f3f3ec..5a0cad4 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)
- branch master updated (b989390 -> 1ae858f), Alex Kost, 2016/01/02
- 02/38: emacs: Add 'guix-with-indent'.,
Alex Kost <=
- 05/38: emacs: list: Generate numerical sort predicates., Alex Kost, 2016/01/02
- 01/38: emacs: Use "cl-list*" instead of "apply #'list"., Alex Kost, 2016/01/02
- 04/38: emacs: Simplify defining parameter titles., Alex Kost, 2016/01/02
- 09/38: emacs: Add 'guix-alist-put'., Alex Kost, 2016/01/02
- 07/38: emacs: list: Configure format in one place., Alex Kost, 2016/01/02
- 12/38: emacs: list: Generalize 'sort-key' code., Alex Kost, 2016/01/02
- 15/38: emacs: list: Factorize "edit package" commands., Alex Kost, 2016/01/02
- 08/38: emacs: Add 'guix-keyword-args-let'., Alex Kost, 2016/01/02
- 10/38: emacs: list: Generalize 'marks' code., Alex Kost, 2016/01/02
- 13/38: emacs: list: Add 'guix-list-mode-initialize'., Alex Kost, 2016/01/02