mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-25 05:48:07 -05:00
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.
This commit is contained in:
parent
de946028be
commit
6ea80938ae
2 changed files with 30 additions and 20 deletions
|
@ -1,6 +1,6 @@
|
||||||
;;; guix-ui.el --- Common code for Guix package management interface -*- lexical-binding: t -*-
|
;;; guix-ui.el --- Common code for Guix package management interface -*- 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.
|
;; This file is part of GNU Guix.
|
||||||
|
|
||||||
|
@ -117,26 +117,10 @@ The function is called with 2 arguments: BASE-NAME and PROFILE."
|
||||||
"Return BASE-NAME."
|
"Return BASE-NAME."
|
||||||
base-name)
|
base-name)
|
||||||
|
|
||||||
;; TODO separate '*...*' logic from the real profile appending. Also add
|
|
||||||
;; another function to return '*Guix ...: /full/path/to/profile*' name.
|
|
||||||
(defun guix-ui-buffer-name-default (base-name profile)
|
(defun guix-ui-buffer-name-default (base-name profile)
|
||||||
"Return buffer name by appending BASE-NAME and PROFILE's base file name."
|
"Return buffer name by appending BASE-NAME and PROFILE's base file name."
|
||||||
(let ((profile-name (file-name-base (directory-file-name profile)))
|
(guix-compose-buffer-name base-name
|
||||||
(re (rx string-start
|
(file-name-base (directory-file-name profile))))
|
||||||
(group (? "*"))
|
|
||||||
(group (*? any))
|
|
||||||
(group (? "*"))
|
|
||||||
string-end)))
|
|
||||||
(or (string-match re base-name)
|
|
||||||
(error "Unexpected error in defining guix 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 ": " profile-name "*")
|
|
||||||
(concat base-name ": " profile-name)))))
|
|
||||||
|
|
||||||
(defun guix-ui-buffer-name (base-name profile)
|
(defun guix-ui-buffer-name (base-name profile)
|
||||||
"Return Guix buffer name based on BASE-NAME and profile.
|
"Return Guix buffer name based on BASE-NAME and profile.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
;;; guix-utils.el --- General utility functions -*- lexical-binding: t -*-
|
;;; 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.
|
;; 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'."
|
See also `guix-copy-as-kill'."
|
||||||
(guix-copy-as-kill (guix-command-string args) no-message?))
|
(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
|
(defun guix-completing-read (prompt table &optional predicate
|
||||||
require-match initial-input
|
require-match initial-input
|
||||||
hist def inherit-input-method)
|
hist def inherit-input-method)
|
||||||
|
|
Loading…
Reference in a new issue