Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

296 lines
14 KiB

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