aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuanma Barranquero2006-11-19 16:56:09 +0000
committerJuanma Barranquero2006-11-19 16:56:09 +0000
commit014d32b1f8a1922734b7baf1acba5a5c2edccfc5 (patch)
tree2c8e91ab6b4128ee17c5168ab96abdcb501b2b3b
parentb733eeef0ecff224bdda576858e4cb6339e967c7 (diff)
downloademacs-014d32b1f8a1922734b7baf1acba5a5c2edccfc5.tar.gz
emacs-014d32b1f8a1922734b7baf1acba5a5c2edccfc5.zip
(glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
a space between an identifier and an opening parenthesis". Defaulted to the `#define' problem of cpp. (glasses-parenthesis-exception-p): New. Check if the region is an exception regarding to that. (glasses-make-readable): Use it. (glasses-convert-to-unreadable): Ditto. Modify the file also if `glasses-convert-on-write-p' and `glasses-separate-parentheses-p' are t.
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/progmodes/glasses.el55
2 files changed, 47 insertions, 19 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 7d2b203463e..49d1cd11bf2 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
12006-11-19 Micha,bk(Bl Cadilhac <michael.cadilhac@lrde.org>
2
3 * progmodes/glasses.el (glasses-separate-parentheses-exceptions): New.
4 Exceptions to the rule "add a space between an identifier and an
5 opening parenthesis". Defaulted to the `#define' problem of cpp.
6 (glasses-parenthesis-exception-p): New. Check if the region is an
7 exception regarding to that.
8 (glasses-make-readable): Use it.
9 (glasses-convert-to-unreadable): Ditto. Modify the file also if
10 `glasses-convert-on-write-p' and `glasses-separate-parentheses-p' are t.
11
12006-11-19 Chong Yidong <cyd@stupidchicken.com> 122006-11-19 Chong Yidong <cyd@stupidchicken.com>
2 13
3 * emacs-lisp/bytecomp.el (byte-compile-if): Revert last change. 14 * emacs-lisp/bytecomp.el (byte-compile-if): Revert last change.
diff --git a/lisp/progmodes/glasses.el b/lisp/progmodes/glasses.el
index dadc9cffc7a..90e6fbe3df3 100644
--- a/lisp/progmodes/glasses.el
+++ b/lisp/progmodes/glasses.el
@@ -110,6 +110,13 @@ but will have their capitals in bold."
110 :group 'glasses 110 :group 'glasses
111 :type 'boolean) 111 :type 'boolean)
112 112
113(defcustom glasses-separate-parentheses-exceptions
114 '("^#[\t ]*define[\t ]*[A-Za-z0-9_-]* ?($")
115 "List of regexp that are exceptions for `glasses-separate-parentheses-p'.
116They are matched to the current line truncated to the point where the
117parenthesis expression starts."
118 :group 'glasses
119 :type '(repeat regexp))
113 120
114(defcustom glasses-uncapitalize-p nil 121(defcustom glasses-uncapitalize-p nil
115 "If non-nil, downcase embedded capital letters in identifiers. 122 "If non-nil, downcase embedded capital letters in identifiers.
@@ -153,6 +160,14 @@ Used in :set parameter of some customized glasses variables."
153 160
154;;; Utility functions 161;;; Utility functions
155 162
163(defun glasses-parenthesis-exception-p (beg end)
164 "Tell if (BEG, END) is an exception to `glasses-separate-parentheses-p'.
165See `glasses-separate-parentheses-exceptions'."
166 (save-match-data
167 (let ((str (buffer-substring beg end)))
168 (catch 'match
169 (dolist (re glasses-separate-parentheses-exceptions)
170 (and (string-match re str) (throw 'match t)))))))
156 171
157(defun glasses-set-overlay-properties () 172(defun glasses-set-overlay-properties ()
158 "Set properties of glasses overlays. 173 "Set properties of glasses overlays.
@@ -232,8 +247,9 @@ CATEGORY is the overlay category. If it is nil, use the `glasses' category."
232 (when glasses-separate-parentheses-p 247 (when glasses-separate-parentheses-p
233 (goto-char beg) 248 (goto-char beg)
234 (while (re-search-forward "[a-zA-Z]_*\\(\(\\)" end t) 249 (while (re-search-forward "[a-zA-Z]_*\\(\(\\)" end t)
235 (glasses-make-overlay (match-beginning 1) (match-end 1) 250 (unless (glasses-parenthesis-exception-p (point-at-bol) (match-end 1))
236 'glasses-parenthesis))))))) 251 (glasses-make-overlay (match-beginning 1) (match-end 1)
252 'glasses-parenthesis))))))))
237 253
238 254
239(defun glasses-make-unreadable (beg end) 255(defun glasses-make-unreadable (beg end)
@@ -247,30 +263,31 @@ CATEGORY is the overlay category. If it is nil, use the `glasses' category."
247 "Convert current buffer to unreadable identifiers and return nil. 263 "Convert current buffer to unreadable identifiers and return nil.
248This function modifies buffer contents, it removes all the separators, 264This function modifies buffer contents, it removes all the separators,
249recognized according to the current value of the variable `glasses-separator'." 265recognized according to the current value of the variable `glasses-separator'."
250 (when (and glasses-convert-on-write-p 266 (when glasses-convert-on-write-p
251 (not (string= glasses-separator "")))
252 (let ((case-fold-search nil) 267 (let ((case-fold-search nil)
253 (separator (regexp-quote glasses-separator))) 268 (separator (regexp-quote glasses-separator)))
254 (save-excursion 269 (save-excursion
255 (goto-char (point-min)) 270 (unless (string= glasses-separator "")
256 (while (re-search-forward
257 (format "[a-z]\\(%s\\)[A-Z]\\|[A-Z]\\(%s\\)[A-Z][a-z]"
258 separator separator)
259 nil t)
260 (let ((n (if (match-string 1) 1 2)))
261 (replace-match "" t nil nil n)
262 (goto-char (match-end n))))
263 (unless (string= glasses-separator glasses-original-separator)
264 (goto-char (point-min)) 271 (goto-char (point-min))
265 (while (re-search-forward (format "[a-zA-Z0-9]\\(%s+\\)[a-zA-Z0-9]" 272 (while (re-search-forward
266 separator) 273 (format "[a-z]\\(%s\\)[A-Z]\\|[A-Z]\\(%s\\)[A-Z][a-z]"
267 nil t) 274 separator separator)
268 (replace-match glasses-original-separator nil nil nil 1) 275 nil t)
269 (goto-char (match-beginning 1)))) 276 (let ((n (if (match-string 1) 1 2)))
277 (replace-match "" t nil nil n)
278 (goto-char (match-end n))))
279 (unless (string= glasses-separator glasses-original-separator)
280 (goto-char (point-min))
281 (while (re-search-forward (format "[a-zA-Z0-9]\\(%s+\\)[a-zA-Z0-9]"
282 separator)
283 nil t)
284 (replace-match glasses-original-separator nil nil nil 1)
285 (goto-char (match-beginning 1)))))
270 (when glasses-separate-parentheses-p 286 (when glasses-separate-parentheses-p
271 (goto-char (point-min)) 287 (goto-char (point-min))
272 (while (re-search-forward "[a-zA-Z]_*\\( \\)\(" nil t) 288 (while (re-search-forward "[a-zA-Z]_*\\( \\)\(" nil t)
273 (replace-match "" t nil nil 1)))))) 289 (unless (glasses-parenthesis-exception-p (point-at-bol) (1+ (match-end 1)))
290 (replace-match "" t nil nil 1)))))))
274 ;; nil must be returned to allow use in write file hooks 291 ;; nil must be returned to allow use in write file hooks
275 nil) 292 nil)
276 293