annotate lisp/progmodes/glasses.el @ 28253:3c4e375505f0

*** empty log message ***
author Kenichi Handa <handa@m17n.org>
date Wed, 22 Mar 2000 01:51:06 +0000
parents 98f24cb3efa5
children 809168962c9b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1 ;;; glasses.el --- make cantReadThis readable
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1999 Free Software Foundation, Inc.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 ;; Author: Milan Zamazal <pdm@freesoft.cz>
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; Maintainer: Milan Zamazal <pdm@freesoft.cz>
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 ;; Keywords: tools
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; any later version.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 ;; This file defines a minor mode for making unreadableIdentifiersLikeThis
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 ;; readable. In some environments, for instance Java, it is common to use such
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ;; unreadable identifiers. It is not good to use underscores in identifiers of
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 ;; your own project in such an environment to make your sources more readable,
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 ;; since it introduces undesirable confusion, which is worse than the
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 ;; unreadability. Fortunately, you use Emacs for the subproject, so the
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 ;; problem can be solved some way.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 ;;
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 ;; This file defines the `glasses-mode' minor mode, which displays underscores
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 ;; between all the pairs of lower and upper English letters. (This only
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 ;; displays underscores, the text is not changed actually.) Alternatively, you
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;; can say you want the capitals in some given face (e.g. bold).
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 ;;
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 ;; The mode does something usable, though not perfect. Improvement suggestions
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 ;; from Emacs experts are welcome.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 ;;
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 ;; If you like in-identifier separators different from underscores, change the
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 ;; value of the variable `glasses-separator' appropriately. See also the
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 ;; variables `glasses-face' and `glasses-convert-on-write-p'. You can also use
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 ;; the command `M-x customize-group RET glasses RET'.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 ;;
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 ;; If you set any of the variables `glasses-separator' or `glasses-face' after
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 ;; glasses.el is loaded and in a different way than through customize, you
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 ;; should call the function `glasses-set-overlay-properties' afterwards.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 ;;; Code:
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 (eval-when-compile
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 (require 'cl))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 ;;; User variables
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 (defgroup glasses nil
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 "Make unreadable identifiers likeThis readable."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 :group 'tools)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 (defcustom glasses-separator "_"
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 "*String to be displayed as a visual separator in unreadable identifiers."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 :group 'glasses
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 :type 'string
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 :set 'glasses-custom-set
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 :initialize 'custom-initialize-default)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 (defcustom glasses-face nil
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 "*Face to be put on capitals of an identifier looked through glasses.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 If it is nil, no face is placed at the capitalized letter.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 For example, you can set `glasses-separator' to an empty string and
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 `glasses-face' to `bold'. Then unreadable identifiers will have no separators,
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 but will have their capitals in bold."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 :group 'glasses
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 :type 'symbol
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 :set 'glasses-custom-set
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 :initialize 'custom-initialize-default)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 (defcustom glasses-convert-on-write-p nil
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 "*If non-nil, remove separators when writing glasses buffer to a file.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 If you are confused by glasses so much, that you write the separators into code
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 during coding, set this variable to t. The separators will be removed on each
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 file write then.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 Note the removal action does not try to be much clever, so it can remove real
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 separators too."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 :group 'glasses
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 :type 'boolean)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 (defun glasses-custom-set (symbol value)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 "Set value of the variable SYMBOL to VALUE and update overlay categories.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 Used in :set parameter of some customized glasses variables."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 (set symbol value)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 (glasses-set-overlay-properties))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 ;;; Utility functions
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 (defun glasses-set-overlay-properties ()
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 "Set properties of glasses overlays.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 Consider current setting of user variables."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114 ;; In-identifier overlay
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 (put 'glasses 'evaporate t)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116 (put 'glasses 'before-string glasses-separator)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 (put 'glasses 'face glasses-face)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 ;; Beg-identifier overlay
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 (put 'glasses-init 'evaporate t)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 (put 'glasses-init 'face glasses-face))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122 (glasses-set-overlay-properties)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 (defun glasses-overlay-p (overlay)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 "Return whether OVERLAY is an overlay of glasses mode."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 (memq (overlay-get overlay 'category) '(glasses glasses-init)))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 (defun glasses-make-overlay (beg end &optional init)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 "Create readability overlay over the region from BEG to END.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 If INIT is non-nil, put `glasses-init' overlay there."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 (let ((overlay (make-overlay beg end)))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 (overlay-put overlay 'category (if init 'glasses-init 'glasses))))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 (defun glasses-make-readable (beg end)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 "Make identifiers in the region from BEG to END readable."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 (let ((case-fold-search nil))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 (save-excursion
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 (save-match-data
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 ;; Face only
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 (goto-char beg)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 (while (re-search-forward
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 "\\<\\([A-Z]\\)[a-zA-Z]*\\([a-z][A-Z]\\|[A-Z][a-z]\\)"
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 end t)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 (glasses-make-overlay (match-beginning 1) (match-end 1) t))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 (goto-char beg)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 ;; Face + separator
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 (while (re-search-forward "[a-z]\\([A-Z]\\)\\|[A-Z]\\([A-Z]\\)[a-z]"
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 end t)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 (let ((n (if (match-string 1) 1 2)))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 (glasses-make-overlay (match-beginning n) (match-end n))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 (goto-char (match-beginning n))))))))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 (defun glasses-make-unreadable (beg end)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 "Return identifiers in the region from BEG to END to their unreadable state."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 (dolist (o (overlays-in beg end))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 (when (glasses-overlay-p o)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 (delete-overlay o))))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 (defun glasses-convert-to-unreadable ()
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 "Convert current buffer to unreadable identifiers and return nil.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 This function modifies buffer contents, it removes all the separators,
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 recognized according to the current value of the variable `glasses-separator'."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 (when (and glasses-convert-on-write-p
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 (not (string= glasses-separator "")))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 (let ((case-fold-search nil))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 (save-excursion
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 (goto-char (point-min))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 (while (re-search-forward
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 "[a-z]\\(_\\)[A-Z]\\|[A-Z]\\(_\\)[A-Z][a-z]" nil t)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 (let ((n (if (match-string 1) 1 2)))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 (replace-match "" t nil nil n)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 (goto-char (match-end n)))))))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 ;; nil must be returned to allow use in write file hooks
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 nil)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 (defun glasses-change (beg end old-len)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 "After-change function updating glass overlays."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 (let ((beg-line (save-excursion (goto-char beg) (line-beginning-position)))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 (end-line (save-excursion (goto-char end) (line-end-position))))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186 (glasses-make-unreadable beg-line end-line)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 (glasses-make-readable beg-line end-line)))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 ;;; Minor mode definition
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 (defvar glasses-mode nil
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194 "Mode variable for `glasses-mode'.")
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 (make-variable-buffer-local 'glasses-mode)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 (add-to-list 'minor-mode-alist '(glasses-mode " o^o"))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 ;;;###autoload
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 (defun glasses-mode (arg)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 "Minor mode for making identifiers likeThis readable.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 When this mode is active, it tries to add virtual separators (like underscores)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 at places they belong to."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205 (interactive "P")
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 (let ((new-flag (if (null arg)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 (not glasses-mode)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 (> (prefix-numeric-value arg) 0))))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 (unless (eq new-flag glasses-mode)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 (save-excursion
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 (save-restriction
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 (widen)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 (if new-flag
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 (progn
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 (glasses-make-readable (point-min) (point-max))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216 (make-local-hook 'after-change-functions)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 (add-hook 'after-change-functions 'glasses-change nil t)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 (add-hook 'local-write-file-hooks
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 'glasses-convert-to-unreadable nil t))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 (glasses-make-unreadable (point-min) (point-max))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 (remove-hook 'after-change-functions 'glasses-change t)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222 (remove-hook 'local-write-file-hooks
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 'glasses-convert-to-unreadable t))))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 (setq glasses-mode new-flag))))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 ;;; Announce
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 (provide 'glasses)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 ;;; glasses.el ends here