[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
15/23: emacs: Add minibuffer readers.
From: |
Alex Kost |
Subject: |
15/23: emacs: Add minibuffer readers. |
Date: |
Sun, 30 Aug 2015 15:28:15 +0000 |
alezost pushed a commit to branch master
in repository guix.
commit d007d8a10cbc3100fe71b61add8eb7723a1c93e8
Author: Alex Kost <address@hidden>
Date: Wed Aug 12 21:01:41 2015 +0300
emacs: Add minibuffer readers.
* emacs/guix-read.el: New file.
* emacs.am (ELFILES): Add it.
---
emacs.am | 1 +
emacs/guix-read.el | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 177 insertions(+), 0 deletions(-)
diff --git a/emacs.am b/emacs.am
index e426653..18ff091 100644
--- a/emacs.am
+++ b/emacs.am
@@ -29,6 +29,7 @@ ELFILES = \
emacs/guix-messages.el \
emacs/guix-pcomplete.el \
emacs/guix-prettify.el \
+ emacs/guix-read.el \
emacs/guix-utils.el \
emacs/guix.el
diff --git a/emacs/guix-read.el b/emacs/guix-read.el
new file mode 100644
index 0000000..5a7201c
--- /dev/null
+++ b/emacs/guix-read.el
@@ -0,0 +1,176 @@
+;;; guix-read.el --- Minibuffer readers
+
+;; Copyright © 2015 Alex Kost <address@hidden>
+
+;; 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 functions to prompt a user for packages, system
+;; types, hash formats and other guix related stuff.
+
+;;; Code:
+
+(require 'guix-help-vars)
+(require 'guix-utils)
+(require 'guix-base)
+
+(defun guix-read-file-name (prompt &optional dir default-filename
+ mustmatch initial predicate)
+ "Read file name.
+This function is similar to `read-file-name' except it also
+expands the file name."
+ (expand-file-name (read-file-name prompt dir default-filename
+ mustmatch initial predicate)))
+
+(defmacro guix-define-reader (name read-fun completions prompt)
+ "Define NAME function to read from minibuffer.
+READ-FUN may be `completing-read', `completing-read-multiple' or
+another function with the same arguments."
+ `(defun ,name (&optional prompt initial-contents)
+ (,read-fun ,(if prompt
+ `(or prompt ,prompt)
+ 'prompt)
+ ,completions nil nil initial-contents)))
+
+(defmacro guix-define-readers (&rest args)
+ "Define reader functions.
+
+ARGS should have a form [KEYWORD VALUE] ... The following
+keywords are available:
+
+ - `completions-var' - variable used to get completions.
+
+ - `completions-getter' - function used to get completions.
+
+ - `single-reader', `single-prompt' - name of a function to read
+ a single value, and a prompt for it.
+
+ - `multiple-reader', `multiple-prompt' - name of a function to
+ read multiple values, and a prompt for it.
+
+ - `multiple-separator' - if specified, another
+ `<multiple-reader-name>-string' function returning a string
+ of multiple values separated the specified separator will be
+ defined."
+ (let (completions-var
+ completions-getter
+ single-reader
+ single-prompt
+ multiple-reader
+ multiple-prompt
+ multiple-separator)
+
+ ;; Process the keyword args.
+ (while (keywordp (car args))
+ (pcase (pop args)
+ (`:completions-var (setq completions-var (pop args)))
+ (`:completions-getter (setq completions-getter (pop args)))
+ (`:single-reader (setq single-reader (pop args)))
+ (`:single-prompt (setq single-prompt (pop args)))
+ (`:multiple-reader (setq multiple-reader (pop args)))
+ (`:multiple-prompt (setq multiple-prompt (pop args)))
+ (`:multiple-separator (setq multiple-separator (pop args)))
+ (_ (pop args))))
+
+ (let ((completions
+ (cond ((and completions-var completions-getter)
+ `(or ,completions-var
+ (setq ,completions-var
+ (funcall ',completions-getter))))
+ (completions-var
+ completions-var)
+ (completions-getter
+ `(funcall ',completions-getter)))))
+ `(progn
+ ,(when (and completions-var
+ (not (boundp completions-var)))
+ `(defvar ,completions-var nil))
+
+ ,(when single-reader
+ `(guix-define-reader ,single-reader completing-read
+ ,completions ,single-prompt))
+
+ ,(when multiple-reader
+ `(guix-define-reader ,multiple-reader completing-read-multiple
+ ,completions ,multiple-prompt))
+
+ ,(when (and multiple-reader multiple-separator)
+ (let ((name (intern (concat (symbol-name multiple-reader)
+ "-string"))))
+ `(defun ,name (&optional prompt initial-contents)
+ (guix-concat-strings
+ (,multiple-reader prompt initial-contents)
+ ,multiple-separator))))))))
+
+(guix-define-readers
+ :completions-var guix-help-system-types
+ :single-reader guix-read-system-type
+ :single-prompt "System type: ")
+
+(guix-define-readers
+ :completions-var guix-help-source-types
+ :single-reader guix-read-source-type
+ :single-prompt "Source type: ")
+
+(guix-define-readers
+ :completions-var guix-help-hash-formats
+ :single-reader guix-read-hash-format
+ :single-prompt "Hash format: ")
+
+(guix-define-readers
+ :completions-var guix-help-refresh-subsets
+ :single-reader guix-read-refresh-subset
+ :single-prompt "Refresh subset: ")
+
+(guix-define-readers
+ :completions-var guix-help-key-policies
+ :single-reader guix-read-key-policy
+ :single-prompt "Key policy: ")
+
+(guix-define-readers
+ :completions-var guix-help-elpa-archives
+ :single-reader guix-read-elpa-archive
+ :single-prompt "ELPA archive: ")
+
+(guix-define-readers
+ :completions-var guix-help-verify-options
+ :multiple-reader guix-read-verify-options
+ :multiple-prompt "Verify option,s: "
+ :multiple-separator ",")
+
+(guix-define-readers
+ :completions-getter guix-graph-type-names
+ :single-reader guix-read-graph-type
+ :single-prompt "Graph node type: ")
+
+(guix-define-readers
+ :completions-getter guix-lint-checker-names
+ :multiple-reader guix-read-lint-checker-names
+ :multiple-prompt "Linter,s: "
+ :multiple-separator ",")
+
+(guix-define-readers
+ :completions-getter guix-package-names
+ :single-reader guix-read-package-name
+ :single-prompt "Package: "
+ :multiple-reader guix-read-package-names
+ :multiple-prompt "Package,s: "
+ :multiple-separator " ")
+
+(provide 'guix-read)
+
+;;; guix-read.el ends here
- 05/23: emacs: Add utils to make symbol and string for guix command., (continued)
- 05/23: emacs: Add utils to make symbol and string for guix command., Alex Kost, 2015/08/30
- 09/23: guix lint: Export checkers and <lint-checker> accessors., Alex Kost, 2015/08/30
- 06/23: emacs: Add utils to copy guix command., Alex Kost, 2015/08/30
- 08/23: emacs: Add 'guix-memoized-defalias' macro., Alex Kost, 2015/08/30
- 07/23: emacs: Add 'guix-any'., Alex Kost, 2015/08/30
- 10/23: emacs: Add 'guix-lint-checker-names'., Alex Kost, 2015/08/30
- 17/23: ui: Add 'run-guix'., Alex Kost, 2015/08/30
- 11/23: guix graph: Export node types and <node-type> accessors., Alex Kost, 2015/08/30
- 12/23: emacs: Add 'guix-graph-type-names'., Alex Kost, 2015/08/30
- 18/23: emacs: Add code to run guix command in REPL., Alex Kost, 2015/08/30
- 15/23: emacs: Add minibuffer readers.,
Alex Kost <=
- 19/23: emacs: Add code to run guix command in shell., Alex Kost, 2015/08/30
- 13/23: emacs: Add 'guix-package-names'., Alex Kost, 2015/08/30
- 14/23: emacs: Add help variables., Alex Kost, 2015/08/30
- 21/23: emacs: Add "guix-popup.el"., Alex Kost, 2015/08/30
- 20/23: doc: Reorganize "Emacs Interface" node., Alex Kost, 2015/08/30
- 23/23: emacs: Use prompt for packages instead popup for edit action., Alex Kost, 2015/08/30
- 16/23: emacs: Add and use alist accessors., Alex Kost, 2015/08/30
- 22/23: emacs: Add popup interface for guix commands., Alex Kost, 2015/08/30