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