[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Rename `eww' to `web'
From: |
Juanma Barranquero |
Subject: |
Re: Rename `eww' to `web' |
Date: |
Fri, 5 Jul 2013 14:59:15 +0200 |
;;; dispatcher.el --- generic command dispatcher -*- lexical-binding: t -*-
;; Copyright (C) 2013 Free Software Foundation, Inc.
;; Author: Juanma Barranquero <address@hidden>
;; Maintainer: FSF
;; Keywords:
;; This file is part of GNU Emacs.
;; GNU Emacs 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 Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Defines a new macro `define-dispatcher' to create generic commands.
;; Generic commands are ones (like web, mail, news, encrypt, irc, etc.)
;; that can have different alternative implementations where choosing
;; among them is exclusively a matter of user preference.
;; (define-dispatcher COMMAND) creates a new interactive command
;; M-x COMMAND and a customizable variable dispatcher-COMMAND-alternatives.
;; Typically, the user will not need to customize this variable; packages
;; wanting to add alternative implementations should use
;;
;; ;;;###autoload (push '("My impl name" . my-impl-symbol)
dispatcher-COMMAND-alternatives
;;; Code:
(defgroup dispatcher nil
"Generic dispatcher"
:group 'applications)
(defmacro define-dispatcher (command &rest customizations)
"Define new command `COMMAND'.
The variable `dispatcher-COMMAND-alternatives' will contain
alternative implementations of COMMAND, so that running
`C-u M-x COMMAND' will allow the user to chose among them.
CUSTOMIZATIONS, if non-nil, should be composed of alternating
`defcustom' keywords and values to add to the declaration of
`dispatcher-COMMAND-alternatives' (typically to add new groups)."
(let* ((command-name (symbol-name command))
(varalt-name (concat "dispatcher-" command-name "-alternatives"))
(varalt-sym (intern varalt-name))
(varimp-sym (intern (concat "dispatcher--" command-name
"-implementation"))))
`(progn
(defcustom ,varalt-sym nil
,(format "Alist of alternative implementations for the `%s' command.
Each entry must be a pair (ALTNAME . ALTFUN), where:
ALTNAME - The name shown at user to describe the alternative implementation.
ALTFUN - The function called to implement this alternative."
command-name)
:type '(alist :key-type string :value-type function)
:group 'dispatcher
,@customizations)
(defvar ,varimp-sym nil "Internal use only.")
(defun ,command (&optional arg)
,(format "Run generic command `%s'.
If used for the first time, or with interactive ARG, ask the user which
implementation to use for `%s'. The variable `%s'
contains the list of implementations currently supported for this command."
command-name command-name varalt-name)
(interactive "P")
(when (or arg (null ,varimp-sym))
(let ((val (completing-read
,(format "Select implementation for command
`%s': " command-name)
,varalt-sym nil t)))
(unless (string-equal val "")
(customize-save-variable ',varimp-sym
(cdr (assoc-string val ,varalt-sym))))))
(if ,varimp-sym
(funcall ,varimp-sym)
(message ,(format "No implementation selected for commmand `%s'"
command-name)))))))
(provide 'dispatcher)
;;; dispatcher.el ends here
dispatcher.el
Description: Binary data
- Re: Rename `eww' to `web', (continued)
- Re: Rename `eww' to `web', Jambunathan K, 2013/07/04
- Re: Rename `eww' to `web', Xue Fuqiao, 2013/07/04
- Re: Rename `eww' to `web', Juri Linkov, 2013/07/04
- Re: Rename `eww' to `web', Xue Fuqiao, 2013/07/05
- Re: Rename `eww' to `web', Juri Linkov, 2013/07/05
- Re: Rename `eww' to `web', Xue Fuqiao, 2013/07/05
- Re: Rename `eww' to `web', Glenn Morris, 2013/07/04
- Re: Rename `eww' to `web', Juanma Barranquero, 2013/07/04
- Re: Rename `eww' to `web', Stefan Monnier, 2013/07/05
- Re: Rename `eww' to `web', Juanma Barranquero, 2013/07/05
- Re: Rename `eww' to `web',
Juanma Barranquero <=
- Re: Rename `eww' to `web', Stefan Monnier, 2013/07/05
- Re: Rename `eww' to `web', Juanma Barranquero, 2013/07/05
- Re: Rename `eww' to `web', Stefan Monnier, 2013/07/05
- Re: Rename `eww' to `web', Juri Linkov, 2013/07/05
- Re: Rename `eww' to `web', Juanma Barranquero, 2013/07/05
- Re: Rename `eww' to `web', Juri Linkov, 2013/07/05
- Re: Rename `eww' to `web', Juanma Barranquero, 2013/07/05
- Re: Rename `eww' to `web', Stefan Monnier, 2013/07/05
- Re: Rename `eww' to `web', Richard Stallman, 2013/07/06
- Re: Rename `eww' to `web', Juri Linkov, 2013/07/04