diff options
author | Alex Kost <alezost@gmail.com> | 2016-04-02 21:07:09 +0300 |
---|---|---|
committer | Alex Kost <alezost@gmail.com> | 2016-04-15 11:32:36 +0300 |
commit | 6ea80938aedd3ec4d7f5d7fd80b7da9b1993c577 (patch) | |
tree | 5e78f9b05f177f8d660b8b4a4e87e71a2e0f77c4 /emacs/guix-utils.el | |
parent | de946028beb4e90495c77bd08b86f75765095b42 (diff) | |
download | guix-6ea80938aedd3ec4d7f5d7fd80b7da9b1993c577.tar guix-6ea80938aedd3ec4d7f5d7fd80b7da9b1993c577.tar.gz |
emacs: Factorize code for buffer names.
* emacs/guix-ui.el (guix-ui-buffer-name-default): Extract the code to
compose buffer name and move to...
* emacs/guix-utils.el (guix-compose-buffer-name): ... here. New procedure.
Diffstat (limited to 'emacs/guix-utils.el')
-rw-r--r-- | emacs/guix-utils.el | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/emacs/guix-utils.el b/emacs/guix-utils.el index 8c1a5b42de..ea9933f5c3 100644 --- a/emacs/guix-utils.el +++ b/emacs/guix-utils.el @@ -1,6 +1,6 @@ ;;; guix-utils.el --- General utility functions -*- lexical-binding: t -*- -;; Copyright © 2014, 2015 Alex Kost <alezost@gmail.com> +;; Copyright © 2014, 2015, 2016 Alex Kost <alezost@gmail.com> ;; This file is part of GNU Guix. @@ -223,6 +223,32 @@ If NO-MESSAGE? is non-nil, do not display a message about it." See also `guix-copy-as-kill'." (guix-copy-as-kill (guix-command-string args) no-message?)) +(defun guix-compose-buffer-name (base-name postfix) + "Return buffer name by appending BASE-NAME and POSTFIX. + +In a simple case the result is: + + BASE-NAME: POSTFIX + +If BASE-NAME is wrapped by '*', then the result is: + + *BASE-NAME: POSTFIX*" + (let ((re (rx string-start + (group (? "*")) + (group (*? any)) + (group (? "*")) + string-end))) + (or (string-match re base-name) + (error "Unexpected error in defining buffer name")) + (let ((first* (match-string 1 base-name)) + (name-body (match-string 2 base-name)) + (last* (match-string 3 base-name))) + ;; Handle the case when buffer name is wrapped by '*'. + (if (and (string= "*" first*) + (string= "*" last*)) + (concat "*" name-body ": " postfix "*") + (concat base-name ": " postfix))))) + (defun guix-completing-read (prompt table &optional predicate require-match initial-input hist def inherit-input-method) |