58 |
|
|
59 |
(defun easy-mmode-pretty-mode-name (mode &optional lighter) |
(defun easy-mmode-pretty-mode-name (mode &optional lighter) |
60 |
"Turn the symbol MODE into a string intended for the user. |
"Turn the symbol MODE into a string intended for the user. |
61 |
If provided LIGHTER will be used to help choose capitalization." |
If provided, LIGHTER will be used to help choose capitalization by, |
62 |
|
replacing its case-insensitive matches with the literal string in LIGHTER." |
63 |
(let* ((case-fold-search t) |
(let* ((case-fold-search t) |
64 |
|
;; Produce "Foo-Bar Minor mode" from foo-bar-minor-mode. |
65 |
(name (concat (replace-regexp-in-string |
(name (concat (replace-regexp-in-string |
66 |
|
;; "Foo-Bar-Minor" -> "Foo-Bar minor" |
67 |
"-Minor" " minor" |
"-Minor" " minor" |
68 |
|
;; "foo-bar-minor" -> "Foo-Bar-Minor" |
69 |
(capitalize (replace-regexp-in-string |
(capitalize (replace-regexp-in-string |
70 |
|
;; "foo-bar-minor-mode" -> "foo-bar-minor" |
71 |
"-mode\\'" "" (symbol-name mode)))) |
"-mode\\'" "" (symbol-name mode)))) |
72 |
" mode"))) |
" mode"))) |
73 |
(if (not (stringp lighter)) name |
(if (not (stringp lighter)) name |
74 |
(setq lighter (replace-regexp-in-string "\\`\\s-+\\|\\-s+\\'" "" lighter)) |
;; Strip leading and trailing whitespace from LIGHTER. |
75 |
(replace-regexp-in-string lighter lighter name t t)))) |
(setq lighter (replace-regexp-in-string "\\`\\s-+\\|\\s-+\\'" "" |
76 |
|
lighter)) |
77 |
|
;; Replace any (case-insensitive) matches for LIGHTER in NAME |
78 |
|
;; with a literal LIGHTER. E.g., if NAME is "Iimage mode" and |
79 |
|
;; LIGHTER is " iImag", then this will produce "iImage mode". |
80 |
|
;; (LIGHTER normally comes from the mode-line string passed to |
81 |
|
;; define-minor-mode, and normally includes at least one leading |
82 |
|
;; space.) |
83 |
|
(replace-regexp-in-string (regexp-quote lighter) lighter name t t)))) |
84 |
|
|
85 |
;;;###autoload |
;;;###autoload |
86 |
(defalias 'easy-mmode-define-minor-mode 'define-minor-mode) |
(defalias 'easy-mmode-define-minor-mode 'define-minor-mode) |