aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Kost <alezost@gmail.com>2015-08-12 15:28:55 +0300
committerAlex Kost <alezost@gmail.com>2015-08-30 18:26:01 +0300
commitc10521e97679c35a40926084e049445cc5053254 (patch)
tree86d9739f72b209064e4b5402e1fa25054e1bffd5
parent935d079bb75c1144946ac9e9915a2278896a458d (diff)
downloadguix-c10521e97679c35a40926084e049445cc5053254.tar
guix-c10521e97679c35a40926084e049445cc5053254.tar.gz
emacs: Add and use 'guix-while-search'.
* emacs/guix-utils.el (guix-while-search): New macro. * emacs/guix-pcomplete.el (guix-pcomplete-run-guix-and-search): Use it. * emacs/guix-prettify.el (guix-prettify-decompose-buffer): Likewise.
-rw-r--r--emacs/guix-pcomplete.el3
-rw-r--r--emacs/guix-prettify.el16
-rw-r--r--emacs/guix-utils.el8
3 files changed, 17 insertions, 10 deletions
diff --git a/emacs/guix-pcomplete.el b/emacs/guix-pcomplete.el
index 9ec563cf52..0049c94d38 100644
--- a/emacs/guix-pcomplete.el
+++ b/emacs/guix-pcomplete.el
@@ -105,9 +105,8 @@ Return a list of strings matching REGEXP.
GROUP specifies a parenthesized expression used in REGEXP."
(with-temp-buffer
(apply #'guix-pcomplete-run-guix args)
- (goto-char (point-min))
(let (result)
- (while (re-search-forward regexp nil t)
+ (guix-while-search regexp
(push (match-string-no-properties group) result))
(nreverse result))))
diff --git a/emacs/guix-prettify.el b/emacs/guix-prettify.el
index c74a393adf..24dfbb33e2 100644
--- a/emacs/guix-prettify.el
+++ b/emacs/guix-prettify.el
@@ -1,6 +1,6 @@
;;; guix-prettify.el --- Prettify Guix store file names
-;; Copyright © 2014 Alex Kost <alezost@gmail.com>
+;; Copyright © 2014, 2015 Alex Kost <alezost@gmail.com>
;; This file is part of GNU Guix.
@@ -47,6 +47,8 @@
;;; Code:
+(require 'guix-utils)
+
(defgroup guix-prettify nil
"Prettify Guix store file names."
:prefix "guix-prettify-"
@@ -137,13 +139,11 @@ enabling/disabling `guix-prettify-mode'. If nil, do nothing.")
(remove-text-properties (point-min)
(point-max)
'(composition nil))
- (save-excursion
- (goto-char (point-min))
- (while (re-search-forward guix-prettify-regexp nil t)
- (remove-text-properties
- (match-beginning guix-prettify-regexp-group)
- (match-end guix-prettify-regexp-group)
- '(composition nil))))))))
+ (guix-while-search guix-prettify-regexp
+ (remove-text-properties
+ (match-beginning guix-prettify-regexp-group)
+ (match-end guix-prettify-regexp-group)
+ '(composition nil)))))))
;;;###autoload
(define-minor-mode guix-prettify-mode
diff --git a/emacs/guix-utils.el b/emacs/guix-utils.el
index dc0c58a114..8a0673a3a0 100644
--- a/emacs/guix-utils.el
+++ b/emacs/guix-utils.el
@@ -160,6 +160,14 @@ accessed with KEYS."
(find-file file)
(message "File '%s' does not exist." file)))
+(defmacro guix-while-search (regexp &rest body)
+ "Evaluate BODY after each search for REGEXP in the current buffer."
+ (declare (indent 1) (debug t))
+ `(save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward ,regexp nil t)
+ ,@body)))
+
;;; Diff