summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2005-05-07 15:06:42 +0000
committerEli Zaretskii <eliz@gnu.org>2005-05-07 15:06:42 +0000
commite6469973d4a91ec2a80b0a6abd176892874e1f9b (patch)
treee2f3c860b3583de95e5a360e234e41a2f4ee4bdc /lisp/emacs-lisp
parent06df7f877bf6db98b8540636819d14114160aee6 (diff)
downloademacs-e6469973d4a91ec2a80b0a6abd176892874e1f9b.tar.gz
emacs-e6469973d4a91ec2a80b0a6abd176892874e1f9b.tar.bz2
emacs-e6469973d4a91ec2a80b0a6abd176892874e1f9b.zip
(easy-mmode-pretty-mode-name): Explain
more about the LIGHTER arg's usage in the doc string. Add commentary to clarify what the code does. Fix the regexp that strips whitespace from LIGHTER. Quote LIGHTER before using it, since it could have characters special to regular expressions.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/easy-mmode.el19
1 files changed, 16 insertions, 3 deletions
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index 831ffb2d576..94db7cc586f 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -58,16 +58,29 @@
(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."
+If provided, LIGHTER will be used to help choose capitalization by,
+replacing its case-insensitive matches with the literal string in LIGHTER."
(let* ((case-fold-search t)
+ ;; Produce "Foo-Bar Minor mode" from foo-bar-minor-mode.
(name (concat (replace-regexp-in-string
+ ;; "Foo-Bar-Minor" -> "Foo-Bar minor"
"-Minor" " minor"
+ ;; "foo-bar-minor" -> "Foo-Bar-Minor"
(capitalize (replace-regexp-in-string
+ ;; "foo-bar-minor-mode" -> "foo-bar-minor"
"-mode\\'" "" (symbol-name mode))))
" mode")))
(if (not (stringp lighter)) name
- (setq lighter (replace-regexp-in-string "\\`\\s-+\\|\\-s+\\'" "" lighter))
- (replace-regexp-in-string lighter lighter name t t))))
+ ;; Strip leading and trailing whitespace from LIGHTER.
+ (setq lighter (replace-regexp-in-string "\\`\\s-+\\|\\s-+\\'" ""
+ lighter))
+ ;; Replace any (case-insensitive) matches for LIGHTER in NAME
+ ;; with a literal LIGHTER. E.g., if NAME is "Iimage mode" and
+ ;; LIGHTER is " iImag", then this will produce "iImage mode".
+ ;; (LIGHTER normally comes from the mode-line string passed to
+ ;; define-minor-mode, and normally includes at least one leading
+ ;; space.)
+ (replace-regexp-in-string (regexp-quote lighter) lighter name t t))))
;;;###autoload
(defalias 'easy-mmode-define-minor-mode 'define-minor-mode)