aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Moellmann2000-04-04 15:01:53 +0000
committerGerd Moellmann2000-04-04 15:01:53 +0000
commit170c1b2668a1ea55a0b1aae65e05c11611fbdfaa (patch)
treeb1a957906e310daeb5989f00d2678ad0ff775089
parentbf1de43e9e1a9e17c88ec66db58eeb655230c6c2 (diff)
downloademacs-170c1b2668a1ea55a0b1aae65e05c11611fbdfaa.tar.gz
emacs-170c1b2668a1ea55a0b1aae65e05c11611fbdfaa.zip
Provide facilities for inserting space before left
parentheses and uncapitalization of identifiers. (glasses-mode): Try to remove old overlays in all cases.
-rw-r--r--lisp/progmodes/glasses.el83
1 files changed, 68 insertions, 15 deletions
diff --git a/lisp/progmodes/glasses.el b/lisp/progmodes/glasses.el
index ee66545b702..3a5e96a4618 100644
--- a/lisp/progmodes/glasses.el
+++ b/lisp/progmodes/glasses.el
@@ -1,6 +1,6 @@
1;;; glasses.el --- make cantReadThis readable 1;;; glasses.el --- make cantReadThis readable
2 2
3;; Copyright (C) 1999 Free Software Foundation, Inc. 3;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
4 4
5;; Author: Milan Zamazal <pdm@freesoft.cz> 5;; Author: Milan Zamazal <pdm@freesoft.cz>
6;; Maintainer: Milan Zamazal <pdm@freesoft.cz> 6;; Maintainer: Milan Zamazal <pdm@freesoft.cz>
@@ -47,7 +47,7 @@
47;; the command `M-x customize-group RET glasses RET'. 47;; the command `M-x customize-group RET glasses RET'.
48;; 48;;
49;; If you set any of the variables `glasses-separator' or `glasses-face' after 49;; If you set any of the variables `glasses-separator' or `glasses-face' after
50;; glasses.el is loaded and in a different way than through customize, you 50;; glasses.el is loaded in a different way than through customize, you
51;; should call the function `glasses-set-overlay-properties' afterwards. 51;; should call the function `glasses-set-overlay-properties' afterwards.
52 52
53;;; Code: 53;;; Code:
@@ -61,7 +61,7 @@
61 61
62 62
63(defgroup glasses nil 63(defgroup glasses nil
64 "Make unreadable identifiers likeThis readable." 64 "Make unreadable code likeThis(one) readable."
65 :group 'tools) 65 :group 'tools)
66 66
67 67
@@ -86,6 +86,33 @@ but will have their capitals in bold."
86 :initialize 'custom-initialize-default) 86 :initialize 'custom-initialize-default)
87 87
88 88
89(defcustom glasses-separate-parentheses-p t
90 "*If non-nil, ensure space between an identifier and an opening parenthesis."
91 :group 'glasses
92 :type 'boolean)
93
94
95(defcustom glasses-uncapitalize-p nil
96 "*If non-nil, downcase embedded capital letters in identifiers.
97Only identifiers starting with lower case letters are affected, letters inside
98other identifiers are unchanged."
99 :group 'glasses
100 :type 'boolean
101 :set 'glasses-custom-set
102 :initialize 'custom-initialize-default)
103
104
105(defcustom glasses-uncapitalize-regexp "[a-z]"
106 "*Regexp matching beginnings of words to be uncapitalized.
107Only words starting with this regexp are uncapitalized.
108The regexp is case sensitive.
109It has any effect only when `glasses-uncapitalize-p' is non-nil."
110 :group 'glasses
111 :type 'regexp
112 :set 'glasses-custom-set
113 :initialize 'custom-initialize-default)
114
115
89(defcustom glasses-convert-on-write-p nil 116(defcustom glasses-convert-on-write-p nil
90 "*If non-nil, remove separators when writing glasses buffer to a file. 117 "*If non-nil, remove separators when writing glasses buffer to a file.
91If you are confused by glasses so much, that you write the separators into code 118If you are confused by glasses so much, that you write the separators into code
@@ -117,21 +144,26 @@ Consider current setting of user variables."
117 (put 'glasses 'face glasses-face) 144 (put 'glasses 'face glasses-face)
118 ;; Beg-identifier overlay 145 ;; Beg-identifier overlay
119 (put 'glasses-init 'evaporate t) 146 (put 'glasses-init 'evaporate t)
120 (put 'glasses-init 'face glasses-face)) 147 (put 'glasses-init 'face glasses-face)
148 ;; Parenthesis overlay
149 (put 'glasses-parenthesis 'evaporate t)
150 (put 'glasses-parenthesis 'before-string " "))
121 151
122(glasses-set-overlay-properties) 152(glasses-set-overlay-properties)
123 153
124 154
125(defun glasses-overlay-p (overlay) 155(defun glasses-overlay-p (overlay)
126 "Return whether OVERLAY is an overlay of glasses mode." 156 "Return whether OVERLAY is an overlay of glasses mode."
127 (memq (overlay-get overlay 'category) '(glasses glasses-init))) 157 (memq (overlay-get overlay 'category)
158 '(glasses glasses-init glasses-parenthesis)))
128 159
129 160
130(defun glasses-make-overlay (beg end &optional init) 161(defun glasses-make-overlay (beg end &optional category)
131 "Create readability overlay over the region from BEG to END. 162 "Create and return readability overlay over the region from BEG to END.
132If INIT is non-nil, put `glasses-init' overlay there." 163CATEGORY is the overlay category. If it is nil, use the `glasses' category."
133 (let ((overlay (make-overlay beg end))) 164 (let ((overlay (make-overlay beg end)))
134 (overlay-put overlay 'category (if init 'glasses-init 'glasses)))) 165 (overlay-put overlay 'category (or category 'glasses))
166 overlay))
135 167
136 168
137(defun glasses-make-readable (beg end) 169(defun glasses-make-readable (beg end)
@@ -144,14 +176,28 @@ If INIT is non-nil, put `glasses-init' overlay there."
144 (while (re-search-forward 176 (while (re-search-forward
145 "\\<\\([A-Z]\\)[a-zA-Z]*\\([a-z][A-Z]\\|[A-Z][a-z]\\)" 177 "\\<\\([A-Z]\\)[a-zA-Z]*\\([a-z][A-Z]\\|[A-Z][a-z]\\)"
146 end t) 178 end t)
147 (glasses-make-overlay (match-beginning 1) (match-end 1) t)) 179 (glasses-make-overlay (match-beginning 1) (match-end 1)
148 (goto-char beg) 180 'glasses-init))
149 ;; Face + separator 181 ;; Face + separator
182 (goto-char beg)
150 (while (re-search-forward "[a-z]\\([A-Z]\\)\\|[A-Z]\\([A-Z]\\)[a-z]" 183 (while (re-search-forward "[a-z]\\([A-Z]\\)\\|[A-Z]\\([A-Z]\\)[a-z]"
151 end t) 184 end t)
152 (let ((n (if (match-string 1) 1 2))) 185 (let* ((n (if (match-string 1) 1 2))
153 (glasses-make-overlay (match-beginning n) (match-end n)) 186 (o (glasses-make-overlay (match-beginning n) (match-end n))))
154 (goto-char (match-beginning n)))))))) 187 (goto-char (match-beginning n))
188 (when (and glasses-uncapitalize-p
189 (save-excursion
190 (save-match-data
191 (re-search-backward "\\<.")
192 (looking-at glasses-uncapitalize-regexp))))
193 (overlay-put o 'invisible t)
194 (overlay-put o 'after-string (downcase (match-string n))))))
195 ;; Parentheses
196 (when glasses-separate-parentheses-p
197 (goto-char beg)
198 (while (re-search-forward "[a-zA-Z]\\(\(\\)" end t)
199 (glasses-make-overlay (match-beginning 1) (match-end 1)
200 'glasses-parenthesis)))))))
155 201
156 202
157(defun glasses-make-unreadable (beg end) 203(defun glasses-make-unreadable (beg end)
@@ -174,7 +220,11 @@ recognized according to the current value of the variable `glasses-separator'."
174 "[a-z]\\(_\\)[A-Z]\\|[A-Z]\\(_\\)[A-Z][a-z]" nil t) 220 "[a-z]\\(_\\)[A-Z]\\|[A-Z]\\(_\\)[A-Z][a-z]" nil t)
175 (let ((n (if (match-string 1) 1 2))) 221 (let ((n (if (match-string 1) 1 2)))
176 (replace-match "" t nil nil n) 222 (replace-match "" t nil nil n)
177 (goto-char (match-end n))))))) 223 (goto-char (match-end n))))
224 (when glasses-separate-parentheses-p
225 (goto-char (point-min))
226 (while (re-search-forward "[a-zA-Z]\\( \\)\(" nil t)
227 (replace-match "" t nil nil 1))))))
178 ;; nil must be returned to allow use in write file hooks 228 ;; nil must be returned to allow use in write file hooks
179 nil) 229 nil)
180 230
@@ -212,6 +262,9 @@ at places they belong to."
212 (widen) 262 (widen)
213 (if new-flag 263 (if new-flag
214 (progn 264 (progn
265 ;; We erase the all overlays to avoid dual sight in some
266 ;; circumstances
267 (glasses-make-unreadable (point-min) (point-max))
215 (glasses-make-readable (point-min) (point-max)) 268 (glasses-make-readable (point-min) (point-max))
216 (make-local-hook 'after-change-functions) 269 (make-local-hook 'after-change-functions)
217 (add-hook 'after-change-functions 'glasses-change nil t) 270 (add-hook 'after-change-functions 'glasses-change nil t)