From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Kost Subject: [PATCH 1/2] emacs: Factorize code for buffer names. Date: Sun, 3 Apr 2016 00:05:45 +0300 Message-ID: <1459631146-5482-2-git-send-email-alezost@gmail.com> References: <1459631146-5482-1-git-send-email-alezost@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35202) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1amSkB-0002rk-Hh for guix-devel@gnu.org; Sat, 02 Apr 2016 17:06:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1amSk9-0001jU-5E for guix-devel@gnu.org; Sat, 02 Apr 2016 17:06:07 -0400 Received: from mail-lb0-x242.google.com ([2a00:1450:4010:c04::242]:33895) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1amSk8-0001jO-Ot for guix-devel@gnu.org; Sat, 02 Apr 2016 17:06:05 -0400 Received: by mail-lb0-x242.google.com with SMTP id vk4so14626572lbb.1 for ; Sat, 02 Apr 2016 14:06:04 -0700 (PDT) Received: from localhost.localdomain ([217.107.192.146]) by smtp.gmail.com with ESMTPSA id zk4sm3337388lbb.15.2016.04.02.14.06.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 02 Apr 2016 14:06:03 -0700 (PDT) In-Reply-To: <1459631146-5482-1-git-send-email-alezost@gmail.com> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org * 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. --- emacs/guix-ui.el | 22 +++------------------- emacs/guix-utils.el | 28 +++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/emacs/guix-ui.el b/emacs/guix-ui.el index 9a88efc..47773de 100644 --- a/emacs/guix-ui.el +++ b/emacs/guix-ui.el @@ -1,6 +1,6 @@ ;;; guix-ui.el --- Common code for Guix package management interface -*- lexical-binding: t -*- -;; Copyright © 2014, 2015 Alex Kost +;; Copyright © 2014, 2015, 2016 Alex Kost ;; 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." 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) "Return buffer name by appending BASE-NAME and PROFILE's base file name." - (let ((profile-name (file-name-base (directory-file-name profile))) - (re (rx string-start - (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))))) + (guix-compose-buffer-name base-name + (file-name-base (directory-file-name profile)))) (defun guix-ui-buffer-name (base-name profile) "Return Guix buffer name based on BASE-NAME and profile. diff --git a/emacs/guix-utils.el b/emacs/guix-utils.el index 8c1a5b4..ea9933f 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 +;; Copyright © 2014, 2015, 2016 Alex Kost ;; 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) -- 2.7.3