diff options
Diffstat (limited to 'lisp/emacs-lisp/easy-mmode.el')
-rw-r--r-- | lisp/emacs-lisp/easy-mmode.el | 79 |
1 files changed, 40 insertions, 39 deletions
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index 0d6716a2e63..ee4e36a9eba 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el @@ -51,8 +51,6 @@ ;;; Code: -(eval-when-compile (require 'cl)) - (defun easy-mmode-pretty-mode-name (mode &optional lighter) "Turn the symbol MODE into a string intended for the user. If provided, LIGHTER will be used to help choose capitalization by, @@ -67,7 +65,8 @@ replacing its case-insensitive matches with the literal string in LIGHTER." ;; "foo-bar-minor" -> "Foo-Bar-Minor" (capitalize (replace-regexp-in-string ;; "foo-bar-minor-mode" -> "foo-bar-minor" - "-mode\\'" "" (symbol-name mode)))) + "toggle-\\|-mode\\'" "" + (symbol-name mode)))) " mode"))) (if (not (stringp lighter)) name ;; Strip leading and trailing whitespace from LIGHTER. @@ -99,7 +98,7 @@ the mode if the argument is `toggle'. If DOC is nil this function adds a basic doc-string stating these facts. Optional INIT-VALUE is the initial value of the mode's variable. -Optional LIGHTER is displayed in the modeline when the mode is on. +Optional LIGHTER is displayed in the mode line when the mode is on. Optional KEYMAP is the default keymap bound to the mode keymap. If non-nil, it should be a variable name (whose value is a keymap), or an expression that returns either a keymap or a list of @@ -142,7 +141,8 @@ For example, you could write (define-minor-mode foo-mode \"If enabled, foo on you!\" :lighter \" Foo\" :require 'foo :global t :group 'hassle :version \"27.5\" ...BODY CODE...)" - (declare (debug (&define name stringp + (declare (doc-string 2) + (debug (&define name stringp [&optional [¬ keywordp] sexp &optional [¬ keywordp] sexp &optional [¬ keywordp] sexp] @@ -152,10 +152,10 @@ For example, you could write ;; Allow skipping the first three args. (cond ((keywordp init-value) - (setq body (list* init-value lighter keymap body) + (setq body `(,init-value ,lighter ,keymap ,@body) init-value nil lighter nil keymap nil)) ((keywordp lighter) - (setq body (list* lighter keymap body) lighter nil keymap nil)) + (setq body `(,lighter ,keymap ,@body) lighter nil keymap nil)) ((keywordp keymap) (push keymap body) (setq keymap nil))) (let* ((last-message (make-symbol "last-message")) @@ -181,18 +181,18 @@ For example, you could write ;; Check keys. (while (keywordp (setq keyw (car body))) (setq body (cdr body)) - (case keyw - (:init-value (setq init-value (pop body))) - (:lighter (setq lighter (purecopy (pop body)))) - (:global (setq globalp (pop body))) - (:extra-args (setq extra-args (pop body))) - (:set (setq set (list :set (pop body)))) - (:initialize (setq initialize (list :initialize (pop body)))) - (:group (setq group (nconc group (list :group (pop body))))) - (:type (setq type (list :type (pop body)))) - (:require (setq require (pop body))) - (:keymap (setq keymap (pop body))) - (:variable (setq variable (pop body)) + (pcase keyw + (`:init-value (setq init-value (pop body))) + (`:lighter (setq lighter (purecopy (pop body)))) + (`:global (setq globalp (pop body))) + (`:extra-args (setq extra-args (pop body))) + (`:set (setq set (list :set (pop body)))) + (`:initialize (setq initialize (list :initialize (pop body)))) + (`:group (setq group (nconc group (list :group (pop body))))) + (`:type (setq type (list :type (pop body)))) + (`:require (setq require (pop body))) + (`:keymap (setq keymap (pop body))) + (`:variable (setq variable (pop body)) (if (not (and (setq tmp (cdr-safe variable)) (or (symbolp tmp) (functionp tmp)))) @@ -200,8 +200,8 @@ For example, you could write (setq mode variable) (setq mode (car variable)) (setq setter (cdr variable)))) - (:after-hook (setq after-hook (pop body))) - (t (push keyw extra-keywords) (push (pop body) extra-keywords)))) + (`:after-hook (setq after-hook (pop body))) + (_ (push keyw extra-keywords) (push (pop body) extra-keywords)))) (setq keymap-sym (if (and keymap (symbolp keymap)) keymap (intern (concat mode-name "-map")))) @@ -228,6 +228,7 @@ For example, you could write (variable nil) ((not globalp) `(progn + :autoload-end (defvar ,mode ,init-value ,(format "Non-nil if %s is enabled. Use the command `%s' to change this variable." pretty-name mode)) (make-variable-buffer-local ',mode))) @@ -335,7 +336,7 @@ enabled, then disabling and reenabling MODE should make MODE work correctly with the current major mode. This is important to prevent problems with derived modes, that is, major modes that call another major mode in their body." - + (declare (doc-string 2)) (let* ((global-mode-name (symbol-name global-mode)) (pretty-name (easy-mmode-pretty-mode-name mode)) (pretty-global-name (easy-mmode-pretty-mode-name global-mode)) @@ -353,10 +354,10 @@ call another major mode in their body." ;; Check keys. (while (keywordp (setq keyw (car keys))) (setq keys (cdr keys)) - (case keyw - (:group (setq group (nconc group (list :group (pop keys))))) - (:global (setq keys (cdr keys))) - (t (push keyw extra-keywords) (push (pop keys) extra-keywords)))) + (pcase keyw + (`:group (setq group (nconc group (list :group (pop keys))))) + (`:global (setq keys (cdr keys))) + (_ (push keyw extra-keywords) (push (pop keys) extra-keywords)))) (unless group ;; We might as well provide a best-guess default group. @@ -365,8 +366,10 @@ call another major mode in their body." "-mode\\'" "" (symbol-name mode)))))) `(progn - (defvar ,MODE-major-mode nil) - (make-variable-buffer-local ',MODE-major-mode) + (progn + :autoload-end + (defvar ,MODE-major-mode nil) + (make-variable-buffer-local ',MODE-major-mode)) ;; The actual global minor-mode (define-minor-mode ,global-mode ;; Very short lines to avoid too long lines in the generated @@ -475,13 +478,13 @@ Valid keywords and arguments are: (while args (let ((key (pop args)) (val (pop args))) - (case key - (:name (setq name val)) - (:dense (setq dense val)) - (:inherit (setq inherit val)) - (:suppress (setq suppress val)) - (:group) - (t (message "Unknown argument %s in defmap" key))))) + (pcase key + (`:name (setq name val)) + (`:dense (setq dense val)) + (`:inherit (setq inherit val)) + (`:suppress (setq suppress val)) + (`:group) + (_ (message "Unknown argument %s in defmap" key))))) (unless (keymapp m) (setq bs (append m bs)) (setq m (if dense (make-keymap name) (make-sparse-keymap name)))) @@ -572,8 +575,6 @@ BODY is executed after moving to the destination location." (when was-narrowed (,narrowfun))))))) (unless name (setq name base-name)) `(progn - (add-to-list 'debug-ignored-errors - ,(concat "^No \\(previous\\|next\\) " (regexp-quote name))) (defun ,next-sym (&optional count) ,(format "Go to the next COUNT'th %s." name) (interactive "p") @@ -584,7 +585,7 @@ BODY is executed after moving to the destination location." `(if (not (re-search-forward ,re nil t count)) (if (looking-at ,re) (goto-char (or ,(if endfun `(,endfun)) (point-max))) - (error "No next %s" ,name)) + (user-error "No next %s" ,name)) (goto-char (match-beginning 0)) (when (and (eq (current-buffer) (window-buffer (selected-window))) (called-interactively-p 'interactive)) @@ -603,7 +604,7 @@ BODY is executed after moving to the destination location." (if (< count 0) (,next-sym (- count)) ,(funcall when-narrowed `(unless (re-search-backward ,re nil t count) - (error "No previous %s" ,name))) + (user-error "No previous %s" ,name))) ,@body)) (put ',prev-sym 'definition-name ',base)))) |