From: Alex Kost <alezost@gmail.com>
To: guix-devel@gnu.org
Subject: [PATCH 1/2] emacs: Improve minibuffer messages.
Date: Sun, 02 Nov 2014 14:21:40 +0300 [thread overview]
Message-ID: <87d295u9tn.fsf@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 189 bytes --]
I think that moving "message system" from “guix-base.el” to
“guix-messages.el” would be more convenient. I also made the messages
more verbose (by mentioning a used profile).
[-- Attachment #2: 0001-emacs-Improve-minibuffer-messages.patch --]
[-- Type: text/x-diff, Size: 13431 bytes --]
From 6811c72ea7b3135de1bbe4230f5b012edbfd092b Mon Sep 17 00:00:00 2001
From: Alex Kost <alezost@gmail.com>
Date: Sun, 2 Nov 2014 13:50:27 +0300
Subject: [PATCH 1/2] emacs: Improve minibuffer messages.
* emacs/guix-base.el (guix-messages, guix-result-message): Move to
'guix-messages.el'.
(guix-set-buffer, guix-history-call, guix-redisplay-buffer): Adjust for
the modified 'guix-result-message'.
* emacs/guix-messages.el: New file.
(guix-messages): Add 'profile' argument.
---
emacs/guix-base.el | 113 +++---------------------------------
emacs/guix-messages.el | 154 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 161 insertions(+), 106 deletions(-)
create mode 100644 emacs/guix-messages.el
diff --git a/emacs/guix-base.el b/emacs/guix-base.el
index 9583d49..eb88f37 100644
--- a/emacs/guix-base.el
+++ b/emacs/guix-base.el
@@ -30,6 +30,8 @@
(require 'cl-lib)
(require 'guix-backend)
(require 'guix-utils)
+(require 'guix-history)
+(require 'guix-messages)
\f
;;; Profiles
@@ -565,7 +567,8 @@ If NO-DISPLAY is non-nil, do not switch to the buffer."
(guix-make-history-item)))
(or no-display
(guix-switch-to-buffer buf))))
- (guix-result-message entries entry-type search-type search-vals))
+ (guix-result-message profile entries entry-type
+ search-type search-vals))
(defun guix-show-entries (entries buffer-type entry-type)
"Display ENTRY-TYPE ENTRIES in the current BUFFER-TYPE buffer."
@@ -583,7 +586,8 @@ If NO-DISPLAY is non-nil, do not switch to the buffer."
(guix-show-entries entries buffer-type entry-type)
(guix-set-vars profile entries buffer-type entry-type
search-type search-vals)
- (guix-result-message entries entry-type search-type search-vals))
+ (guix-result-message profile entries entry-type
+ search-type search-vals))
(defun guix-make-history-item ()
"Make and return a history item for the current buffer."
@@ -642,113 +646,10 @@ This function will not update the information, use
\"\\[revert-buffer]\" if you want the full update."
(interactive)
(guix-show-entries guix-entries guix-buffer-type guix-entry-type)
- (guix-result-message guix-entries guix-entry-type
+ (guix-result-message guix-profile guix-entries guix-entry-type
guix-search-type guix-search-vals))
\f
-;;; Messages
-
-(defvar guix-messages
- '((package
- (id
- (0 "Packages not found.")
- (1 "")
- (many "%d packages." count))
- (name
- (0 "The package '%s' not found." val)
- (1 "A single package with name '%s'." val)
- (many "%d packages with '%s' name." count val))
- (regexp
- (0 "No packages matching '%s'." val)
- (1 "A single package matching '%s'." val)
- (many "%d packages matching '%s'." count val))
- (all-available
- (0 "No packages are available for some reason.")
- (1 "A single available package (that's strange).")
- (many "%d available packages." count))
- (newest-available
- (0 "No packages are available for some reason.")
- (1 "A single newest available package (that's strange).")
- (many "%d newest available packages." count))
- (installed
- (0 "No installed packages.")
- (1 "A single package installed.")
- (many "%d packages installed." count))
- (obsolete
- (0 "No obsolete packages.")
- (1 "A single obsolete package.")
- (many "%d obsolete packages." count))
- (generation
- (0 "No packages installed in generation %d." val)
- (1 "A single package installed in generation %d." val)
- (many "%d packages installed in generation %d." count val)))
- (output
- (id
- (0 "Package outputs not found.")
- (1 "")
- (many "%d package outputs." count))
- (name
- (0 "The package output '%s' not found." val)
- (1 "A single package output with name '%s'." val)
- (many "%d package outputs with '%s' name." count val))
- (regexp
- (0 "No package outputs matching '%s'." val)
- (1 "A single package output matching '%s'." val)
- (many "%d package outputs matching '%s'." count val))
- (all-available
- (0 "No package outputs are available for some reason.")
- (1 "A single available package output (that's strange).")
- (many "%d available package outputs." count))
- (newest-available
- (0 "No package outputs are available for some reason.")
- (1 "A single newest available package output (that's strange).")
- (many "%d newest available package outputs." count))
- (installed
- (0 "No installed package outputs.")
- (1 "A single package output installed.")
- (many "%d package outputs installed." count))
- (obsolete
- (0 "No obsolete package outputs.")
- (1 "A single obsolete package output.")
- (many "%d obsolete package outputs." count))
- (generation
- (0 "No package outputs installed in generation %d." val)
- (1 "A single package output installed in generation %d." val)
- (many "%d package outputs installed in generation %d." count val)))
- (generation
- (id
- (0 "Generations not found.")
- (1 "")
- (many "%d generations." count))
- (last
- (0 "No available generations.")
- (1 "The last generation.")
- (many "%d last generations." count))
- (all
- (0 "No available generations.")
- (1 "A single available generation.")
- (many "%d available generations." count))
- (time
- (0 "Generations not found.")
- (1 "A single generation matching time period.")
- (many "%d generations matching time period." count)))))
-
-(defun guix-result-message (entries entry-type search-type search-vals)
- "Display an appropriate message after displaying ENTRIES."
- (let* ((val (car search-vals))
- (count (length entries))
- (count-key (if (> count 1) 'many count))
- (msg-spec (guix-get-key-val guix-messages
- entry-type search-type count-key))
- (format (car msg-spec))
- (args (cdr msg-spec)))
- (mapc (lambda (subst)
- (setq args (cl-substitute (car subst) (cdr subst) args)))
- (list (cons count 'count)
- (cons val 'val)))
- (apply #'message format args)))
-
-\f
;;; Actions on packages and generations
(defface guix-operation-option-key
diff --git a/emacs/guix-messages.el b/emacs/guix-messages.el
new file mode 100644
index 0000000..c77b5c0
--- /dev/null
+++ b/emacs/guix-messages.el
@@ -0,0 +1,154 @@
+;;; guix-messages.el --- Minibuffer messages
+
+;; Copyright © 2014 Alex Kost <alezost@gmail.com>
+
+;; This file is part of GNU Guix.
+
+;; GNU Guix is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Guix is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This file provides `guix-result-message' function used to show a
+;; minibuffer message after displaying packages/generations in a
+;; list/info buffer.
+
+;;; Code:
+
+(require 'cl-lib)
+(require 'guix-utils)
+
+(defvar guix-messages
+ `((package
+ (id
+ (0 "Packages not found.")
+ (1 "")
+ (many "%d packages." count))
+ (name
+ (0 "The package '%s' not found." val)
+ (1 "A single package with name '%s'." val)
+ (many "%d packages with '%s' name." count val))
+ (regexp
+ (0 "No packages matching '%s'." val)
+ (1 "A single package matching '%s'." val)
+ (many "%d packages matching '%s'." count val))
+ (all-available
+ (0 "No packages are available for some reason.")
+ (1 "A single available package (that's strange).")
+ (many "%d available packages." count))
+ (newest-available
+ (0 "No packages are available for some reason.")
+ (1 "A single newest available package (that's strange).")
+ (many "%d newest available packages." count))
+ (installed
+ (0 "No packages installed in profile '%s'." profile)
+ (1 "A single package installed in profile '%s'." profile)
+ (many "%d packages installed in profile '%s'." count profile))
+ (obsolete
+ (0 "No obsolete packages in profile '%s'." profile)
+ (1 "A single obsolete package in profile '%s'." profile)
+ (many "%d obsolete packages in profile '%s'." count profile))
+ (generation
+ (0 "No packages installed in generation %d of profile '%s'."
+ val profile)
+ (1 "A single package installed in generation %d of profile '%s'."
+ val profile)
+ (many "%d packages installed in generation %d of profile '%s'."
+ count val profile)))
+
+ (output
+ (id
+ (0 "Package outputs not found.")
+ (1 "")
+ (many "%d package outputs." count))
+ (name
+ (0 "The package output '%s' not found." val)
+ (1 "A single package output with name '%s'." val)
+ (many "%d package outputs with '%s' name." count val))
+ (regexp
+ (0 "No package outputs matching '%s'." val)
+ (1 "A single package output matching '%s'." val)
+ (many "%d package outputs matching '%s'." count val))
+ (all-available
+ (0 "No package outputs are available for some reason.")
+ (1 "A single available package output (that's strange).")
+ (many "%d available package outputs." count))
+ (newest-available
+ (0 "No package outputs are available for some reason.")
+ (1 "A single newest available package output (that's strange).")
+ (many "%d newest available package outputs." count))
+ (installed
+ (0 "No package outputs installed in profile '%s'." profile)
+ (1 "A single package output installed in profile '%s'." profile)
+ (many "%d package outputs installed in profile '%s'." count profile))
+ (obsolete
+ (0 "No obsolete package outputs in profile '%s'." profile)
+ (1 "A single obsolete package output in profile '%s'." profile)
+ (many "%d obsolete package outputs in profile '%s'." count profile))
+ (generation
+ (0 "No package outputs installed in generation %d of profile '%s'."
+ val profile)
+ (1 "A single package output installed in generation %d of profile '%s'."
+ val profile)
+ (many "%d package outputs installed in generation %d of profile '%s'."
+ count val profile)))
+
+ (generation
+ (id
+ (0 "Generations not found.")
+ (1 "")
+ (many "%d generations." count))
+ (last
+ (0 "No generations in profile '%s'." profile)
+ (1 "The last generation of profile '%s'." profile)
+ (many "%d last generations of profile '%s'." count profile))
+ (all
+ (0 "No generations in profile '%s'." profile)
+ (1 "A single generation available in profile '%s'." profile)
+ (many "%d generations available in profile '%s'." count profile))
+ (time
+ (0 "Generations not found.")
+ (1 ,(lambda (profile entries vals)
+ (let ((beg (guix-get-time-string (car vals)))
+ (end (guix-get-time-string (cadr vals))))
+ (message (concat "A single generation of profile '%s' "
+ "matching time period '%s'/'%s'.")
+ profile beg end))))
+ (many ,(lambda (profile entries vals)
+ (let ((beg (guix-get-time-string (car vals)))
+ (end (guix-get-time-string (cadr vals))))
+ (message (concat "%d generations of profile '%s' "
+ "matching time period '%s'/'%s'.")
+ (length entries) profile beg end))))))))
+
+(defun guix-result-message (profile entries entry-type
+ search-type search-vals)
+ "Display an appropriate message after displaying ENTRIES."
+ (let* ((count (length entries))
+ (count-key (if (> count 1) 'many count))
+ (msg-spec (guix-get-key-val guix-messages
+ entry-type search-type count-key))
+ (fun-or-msg (car msg-spec)))
+ (if (functionp fun-or-msg)
+ (funcall fun-or-msg profile entries search-vals)
+ (let ((args (cdr msg-spec)))
+ (mapc (lambda (subst)
+ (setq args (cl-substitute (cdr subst) (car subst) args)))
+ `((count . ,count)
+ (val . ,(car search-vals))
+ (profile . ,profile)))
+ (apply #'message fun-or-msg args)))))
+
+(provide 'guix-messages)
+
+;;; guix-messages.el ends here
--
2.1.2
next reply other threads:[~2014-11-02 11:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-02 11:21 Alex Kost [this message]
2014-11-02 17:27 ` [PATCH 1/2] emacs: Improve minibuffer messages Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87d295u9tn.fsf@gmail.com \
--to=alezost@gmail.com \
--cc=guix-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).