My personal .emacs.d folder

diminish.el 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. ;;; diminish.el --- Diminished modes are minor modes with no modeline display
  2. ;; Copyright (C) 1998 Free Software Foundation, Inc.
  3. ;; Author: Will Mengarini <seldon@eskimo.com>
  4. ;; Maintainer: Martin Yrjölä <martin.yrjola@gmail.com>
  5. ;; URL: <https://github.com/myrjola/diminish.el>
  6. ;; Created: Th 19 Feb 98
  7. ;; Version: 0.45
  8. ;; Keywords: extensions, diminish, minor, codeprose
  9. ;; This program is free software; you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation; either version 2, or (at your option)
  12. ;; any later version.
  13. ;; This program is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License along with
  18. ;; this program; see the file LICENSE. If not, write to the write to the Free
  19. ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. ;; 02110-1301, USA.
  21. ;;; Commentary:
  22. ;; Minor modes each put a word on the mode line to signify that they're
  23. ;; active. This can cause other displays, such as % of file that point is
  24. ;; at, to run off the right side of the screen. For some minor modes, such
  25. ;; as mouse-avoidance-mode, the display is a waste of space, since users
  26. ;; typically set the mode in their .emacs & never change it. For other
  27. ;; modes, such as my jiggle-mode, it's a waste because there's already a
  28. ;; visual indication of whether the mode is in effect.
  29. ;; A diminished mode is a minor mode that has had its mode line
  30. ;; display diminished, usually to nothing, although diminishing to a
  31. ;; shorter word or a single letter is also supported. This package
  32. ;; implements diminished modes.
  33. ;; You can use this package either interactively or from your .emacs file.
  34. ;; In either case, first you'll need to copy this file to a directory that
  35. ;; appears in your load-path. `load-path' is the name of a variable that
  36. ;; contains a list of directories Emacs searches for files to load.
  37. ;; To prepend another directory to load-path, put a line like
  38. ;; (add-to-list 'load-path "c:/My_Directory") in your .emacs file.
  39. ;; To create diminished modes interactively, type
  40. ;; M-x load-library
  41. ;; to get a prompt like
  42. ;; Load library:
  43. ;; and respond `diminish' (unquoted). Then type
  44. ;; M-x diminish
  45. ;; to get a prompt like
  46. ;; Diminish what minor mode:
  47. ;; and respond with the name of some minor mode, like mouse-avoidance-mode.
  48. ;; You'll then get this prompt:
  49. ;; To what mode-line display:
  50. ;; Respond by just hitting <Enter> if you want the name of the mode
  51. ;; completely removed from the mode line. If you prefer, you can abbreviate
  52. ;; the name. If your abbreviation is 2 characters or more, such as "Av",
  53. ;; it'll be displayed as a separate word on the mode line, just like minor
  54. ;; modes' names. If it's a single character, such as "V", it'll be scrunched
  55. ;; up against the previous word, so for example if the undiminished mode line
  56. ;; display had been "Abbrev Fill Avoid", it would become "Abbrev FillV".
  57. ;; Multiple single-letter diminished modes will all be scrunched together.
  58. ;; The display of undiminished modes will not be affected.
  59. ;; To find out what the mode line would look like if all diminished modes
  60. ;; were still minor, type M-x diminished-modes. This displays in the echo
  61. ;; area the complete list of minor or diminished modes now active, but
  62. ;; displays them all as minor. They remain diminished on the mode line.
  63. ;; To convert a diminished mode back to a minor mode, type M-x diminish-undo
  64. ;; to get a prompt like
  65. ;; Restore what diminished mode:
  66. ;; Respond with the name of some diminished mode. To convert all
  67. ;; diminished modes back to minor modes, respond to that prompt
  68. ;; with `diminished-modes' (unquoted, & note the hyphen).
  69. ;; When you're responding to the prompts for mode names, you can use
  70. ;; completion to avoid extra typing; for example, m o u SPC SPC SPC
  71. ;; is usually enough to specify mouse-avoidance-mode. Mode names
  72. ;; typically end in "-mode", but for historical reasons
  73. ;; auto-fill-mode is named by "auto-fill-function".
  74. ;; To create diminished modes noninteractively in your .emacs file, put
  75. ;; code like
  76. ;; (require 'diminish)
  77. ;; (diminish 'abbrev-mode "Abv")
  78. ;; (diminish 'jiggle-mode)
  79. ;; (diminish 'mouse-avoidance-mode "M")
  80. ;; near the end of your .emacs file. It should be near the end so that any
  81. ;; minor modes your .emacs loads will already have been loaded by the time
  82. ;; they're to be converted to diminished modes.
  83. ;; To diminish a major mode, (setq mode-name "whatever") in the mode hook.
  84. ;;; Epigraph:
  85. ;; "The quality of our thoughts is bordered on all sides
  86. ;; by our facility with language."
  87. ;; --J. Michael Straczynski
  88. ;;; Code:
  89. (eval-when-compile (require 'cl))
  90. (defvar diminish-must-not-copy-minor-mode-alist nil
  91. "Non-nil means loading diminish.el won't (copy-alist minor-mode-alist).
  92. Normally `minor-mode-alist' is setq to that copy on loading diminish because
  93. at least one of its cons cells, that for abbrev-mode, is read-only (see
  94. ELisp Info on \"pure storage\"). If you setq this variable to t & then
  95. try to diminish abbrev-mode under GNU Emacs 19.34, you'll get the error
  96. message \"Attempt to modify read-only object\".")
  97. (or diminish-must-not-copy-minor-mode-alist
  98. (callf copy-alist minor-mode-alist))
  99. (defvar diminished-mode-alist nil
  100. "The original `minor-mode-alist' value of all (diminish)ed modes.")
  101. (defvar diminish-history-symbols nil
  102. "Command history for symbols of diminished modes.")
  103. (defvar diminish-history-names nil
  104. "Command history for names of diminished modes.")
  105. ;; When we diminish a mode, we are saying we want it to continue doing its
  106. ;; work for us, but we no longer want to be reminded of it. It becomes a
  107. ;; night worker, like a janitor; it becomes an invisible man; it remains a
  108. ;; component, perhaps an important one, sometimes an indispensable one, of
  109. ;; the mechanism that maintains the day-people's world, but its place in
  110. ;; their thoughts is diminished, usually to nothing. As we grow old we
  111. ;; diminish more and more such thoughts, such people, usually to nothing.
  112. ;; "The wise man knows that to keep under is to endure." The diminished
  113. ;; often come to value their invisibility. We speak--speak--of "the strong
  114. ;; silent type", but only as a superficiality; a stereotype in a movie,
  115. ;; perhaps, but even if an acquaintance, necessarily, by hypothesis, a
  116. ;; distant one. The strong silent type is actually a process. It begins
  117. ;; with introspection, continues with judgment, and is shaped by the
  118. ;; discovery that these judgments are impractical to share; there is no
  119. ;; appetite for the wisdom of the self-critical among the creatures of
  120. ;; material appetite who dominate our world. Their dominance's Darwinian
  121. ;; implications reinforce the self-doubt that is the germ of higher wisdom.
  122. ;; The thoughtful contemplate the evolutionary triumph of the predator.
  123. ;; Gnostics deny the cosmos could be so evil; this must all be a prank; the
  124. ;; thoughtful remain silent, invisible, self-diminished, and discover,
  125. ;; perhaps at first in surprise, the freedom they thus gain, and grow strong.
  126. ;;;###autoload
  127. (defun diminish (mode &optional to-what)
  128. "Diminish mode-line display of minor mode MODE to TO-WHAT (default \"\").
  129. Interactively, enter (with completion) the name of any minor mode, followed
  130. on the next line by what you want it diminished to (default empty string).
  131. The response to neither prompt should be quoted. However, in Lisp code,
  132. both args must be quoted, the first as a symbol, the second as a string,
  133. as in (diminish 'jiggle-mode \" Jgl\").
  134. The mode-line displays of minor modes usually begin with a space, so
  135. the modes' names appear as separate words on the mode line. However, if
  136. you're having problems with a cramped mode line, you may choose to use single
  137. letters for some modes, without leading spaces. Capitalizing them works
  138. best; if you then diminish some mode to \"X\" but have abbrev-mode enabled as
  139. well, you'll get a display like \"AbbrevX\". This function prepends a space
  140. to TO-WHAT if it's > 1 char long & doesn't already begin with a space."
  141. (interactive (list (read (completing-read
  142. "Diminish what minor mode: "
  143. (mapcar (lambda (x) (list (symbol-name (car x))))
  144. minor-mode-alist)
  145. nil t nil 'diminish-history-symbols))
  146. (read-from-minibuffer
  147. "To what mode-line display: "
  148. nil nil nil 'diminish-history-names)))
  149. (let ((minor (assq mode minor-mode-alist)))
  150. (when minor
  151. (progn (callf or to-what "")
  152. (when (> (length to-what) 1)
  153. (or (= (string-to-char to-what) ?\ )
  154. (callf2 concat " " to-what)))
  155. (or (assq mode diminished-mode-alist)
  156. (push (copy-sequence minor) diminished-mode-alist))
  157. (setcdr minor (list to-what))))))
  158. ;; But an image comes to me, vivid in its unreality, of a loon alone on his
  159. ;; forest lake, shrieking his soul out into a canopy of stars. Alone this
  160. ;; afternoon in my warm city apartment, I can feel the bite of his night air,
  161. ;; and smell his conifers. In him there is no acceptance of diminishment.
  162. ;; "I have a benevolent habit of pouring out myself to everybody,
  163. ;; and would even pay for a listener, and I am afraid
  164. ;; that the Athenians may think me too talkative."
  165. ;; --Socrates, in the /Euthyphro/
  166. ;; I remember a news story about a retired plumber who had somehow managed to
  167. ;; steal a military tank. He rode it down city streets, rode over a parked
  168. ;; car--no one was hurt--rode onto a freeway, that concrete symbol of the
  169. ;; American spirit, or so we fancy it, shouting "Plumber Bob! Plumber Bob!".
  170. ;; He was shot dead by police.
  171. ;;;###autoload
  172. (defun diminish-undo (mode)
  173. "Restore mode-line display of diminished mode MODE to its minor-mode value.
  174. Do nothing if the arg is a minor mode that hasn't been diminished.
  175. Interactively, enter (with completion) the name of any diminished mode (a
  176. mode that was formerly a minor mode on which you invoked \\[diminish]).
  177. To restore all diminished modes to minor status, answer `diminished-modes'.
  178. The response to the prompt shouldn't be quoted. However, in Lisp code,
  179. the arg must be quoted as a symbol, as in (diminish-undo 'diminished-modes)."
  180. (interactive
  181. (list (read (completing-read
  182. "Restore what diminished mode: "
  183. (cons (list "diminished-modes")
  184. (mapcar (lambda (x) (list (symbol-name (car x))))
  185. diminished-mode-alist))
  186. nil t nil 'diminish-history-symbols))))
  187. (if (eq mode 'diminished-modes)
  188. (let ((diminished-modes diminished-mode-alist))
  189. (while diminished-modes
  190. (diminish-undo (caar diminished-modes))
  191. (callf cdr diminished-modes)))
  192. (let ((minor (assq mode minor-mode-alist))
  193. (diminished (assq mode diminished-mode-alist)))
  194. (or minor
  195. (error "%S is not currently registered as a minor mode" mode))
  196. (when diminished
  197. (setcdr minor (cdr diminished))))))
  198. ;; Plumber Bob was not from Seattle, my grey city, for rainy Seattle is a
  199. ;; city of interiors, a city of the self-diminished. When I moved here one
  200. ;; sunny June I was delighted to find that ducks and geese were common in
  201. ;; the streets. But I hoped to find a loon or two, and all I found were
  202. ;; ducks and geese. I wondered about this; I wondered why there were no
  203. ;; loons in Seattle; but my confusion resulted from my ignorance of the
  204. ;; psychology of rain, which is to say my ignorance of diminished modes.
  205. ;; What I needed, and lacked, was a way to discover they were there.
  206. ;;;###autoload
  207. (defun diminished-modes ()
  208. "Echo all active diminished or minor modes as if they were minor.
  209. The display goes in the echo area; if it's too long even for that,
  210. you can see the whole thing in the *Messages* buffer.
  211. This doesn't change the status of any modes; it just lets you see
  212. what diminished modes would be on the mode-line if they were still minor."
  213. (interactive)
  214. (let ((minor-modes minor-mode-alist)
  215. message)
  216. (while minor-modes
  217. (when (symbol-value (caar minor-modes))
  218. ;; This minor mode is active in this buffer
  219. (let* ((mode-pair (car minor-modes))
  220. (mode (car mode-pair))
  221. (minor-pair (or (assq mode diminished-mode-alist) mode-pair))
  222. (minor-name (cadr minor-pair)))
  223. (when (symbolp minor-name)
  224. ;; This minor mode uses symbol indirection in the cdr
  225. (let ((symbols-seen (list minor-name)))
  226. (while (and (symbolp (callf symbol-value minor-name))
  227. (not (memq minor-name symbols-seen)))
  228. (push minor-name symbols-seen))))
  229. (push minor-name message)))
  230. (callf cdr minor-modes))
  231. (setq message (mapconcat 'identity (nreverse message) ""))
  232. (when (= (string-to-char message) ?\ )
  233. (callf substring message 1))
  234. (message "%s" message)))
  235. ;; A human mind is a Black Forest of diminished modes. Some are dangerous;
  236. ;; most of the mind of an intimate is a secret stranger, and these diminished
  237. ;; modes are rendered more unpredictable by their long isolation from the
  238. ;; corrective influence of interaction with reality. The student of history
  239. ;; learns that this description applies to whole societies as well. In some
  240. ;; ways the self-diminished are better able to discern the night worker.
  241. ;; They are rendered safer by their heightened awareness of others'
  242. ;; diminished modes, and more congenial by the spare blandness of their own
  243. ;; mode lines. To some people rain is truly depressing, but others it just
  244. ;; makes pensive, and, forcing them indoors where they may not have the
  245. ;; luxury of solitude, teaches them to self-diminish. That was what I had
  246. ;; not understood when I was searching for loons among the ducks and geese.
  247. ;; Loons come to Seattle all the time, but the ones that like it learn to be
  248. ;; silent, learn to self-diminish, and take on the colors of ducks and geese.
  249. ;; Now, here a dozen years, I can recognize them everywhere, standing quietly
  250. ;; in line with the ducks and geese at the espresso counter, gazing placidly
  251. ;; out on the world through loon-red eyes, thinking secret thoughts.
  252. (provide 'diminish)
  253. ;;; diminish.el ends here