[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Glasses.el and C bug.
From: |
Michaël Cadilhac |
Subject: |
Glasses.el and C bug. |
Date: |
Fri, 17 Nov 2006 02:25:07 +0100 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.90 (gnu/linux) |
When using cpp's #define-s, one has to deal with a huge difference
between
#define FOO(Bar)
and
#define FOO (Bar)
the first one being a macro function, the second one a macro that
expands itself to (Bar).
glasses.el is guilty of adding a space between FOO and (Bar), making
the function looking like a simple macro. It is even more guilty of
actually changing this in the file if `glasses-convert-on-write-p' is
set to t, corrupting the very meaning of the cpp !
The following patch addresses those two problems and a minor another
one (glasses.el has to modify the file also if paren separating is t).
Index: lisp/progmodes/glasses.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/progmodes/glasses.el,v
retrieving revision 1.18
diff -c -r1.18 glasses.el
*** lisp/progmodes/glasses.el 23 Feb 2006 16:35:41 -0000 1.18
--- lisp/progmodes/glasses.el 17 Nov 2006 01:15:43 -0000
***************
*** 110,115 ****
--- 110,122 ----
:group 'glasses
:type 'boolean)
+ (defcustom glasses-separate-parentheses-exceptions
+ '("^#[\t ]*define[\t ]*[A-Za-z0-9_-]* ?($")
+ "List of regexp that are exceptions for `glasses-separate-parentheses-p'.
+ They are matched to the current line truncated to the point where the
+ parenthesis expression starts."
+ :group 'glasses
+ :type '(repeat regexp))
(defcustom glasses-uncapitalize-p nil
"If non-nil, downcase embedded capital letters in identifiers.
***************
*** 153,158 ****
--- 160,173 ----
;;; Utility functions
+ (defun glasses-parenthesis-exception-p (beg end)
+ "Tell if (BEG, END) is an exception to `glasses-separate-parentheses-p'.
+ See `glasses-separate-parentheses-exceptions'."
+ (save-match-data
+ (let ((str (buffer-substring beg end)))
+ (catch 'match
+ (dolist (re glasses-separate-parentheses-exceptions)
+ (and (string-match re str) (throw 'match t)))))))
(defun glasses-set-overlay-properties ()
"Set properties of glasses overlays.
***************
*** 232,239 ****
(when glasses-separate-parentheses-p
(goto-char beg)
(while (re-search-forward "[a-zA-Z]_*\\(\(\\)" end t)
! (glasses-make-overlay (match-beginning 1) (match-end 1)
! 'glasses-parenthesis)))))))
(defun glasses-make-unreadable (beg end)
--- 247,255 ----
(when glasses-separate-parentheses-p
(goto-char beg)
(while (re-search-forward "[a-zA-Z]_*\\(\(\\)" end t)
! (unless (glasses-parenthesis-exception-p (point-at-bol) (match-end
1))
! (glasses-make-overlay (match-beginning 1) (match-end 1)
! 'glasses-parenthesis))))))))
(defun glasses-make-unreadable (beg end)
***************
*** 247,276 ****
"Convert current buffer to unreadable identifiers and return nil.
This function modifies buffer contents, it removes all the separators,
recognized according to the current value of the variable
`glasses-separator'."
! (when (and glasses-convert-on-write-p
! (not (string= glasses-separator "")))
(let ((case-fold-search nil)
(separator (regexp-quote glasses-separator)))
(save-excursion
! (goto-char (point-min))
! (while (re-search-forward
! (format "[a-z]\\(%s\\)[A-Z]\\|[A-Z]\\(%s\\)[A-Z][a-z]"
! separator separator)
! nil t)
! (let ((n (if (match-string 1) 1 2)))
! (replace-match "" t nil nil n)
! (goto-char (match-end n))))
! (unless (string= glasses-separator glasses-original-separator)
(goto-char (point-min))
! (while (re-search-forward (format "[a-zA-Z0-9]\\(%s+\\)[a-zA-Z0-9]"
! separator)
! nil t)
! (replace-match glasses-original-separator nil nil nil 1)
! (goto-char (match-beginning 1))))
(when glasses-separate-parentheses-p
(goto-char (point-min))
(while (re-search-forward "[a-zA-Z]_*\\( \\)\(" nil t)
! (replace-match "" t nil nil 1))))))
;; nil must be returned to allow use in write file hooks
nil)
--- 263,293 ----
"Convert current buffer to unreadable identifiers and return nil.
This function modifies buffer contents, it removes all the separators,
recognized according to the current value of the variable
`glasses-separator'."
! (when glasses-convert-on-write-p
(let ((case-fold-search nil)
(separator (regexp-quote glasses-separator)))
(save-excursion
! (unless (string= glasses-separator "")
(goto-char (point-min))
! (while (re-search-forward
! (format "[a-z]\\(%s\\)[A-Z]\\|[A-Z]\\(%s\\)[A-Z][a-z]"
! separator separator)
! nil t)
! (let ((n (if (match-string 1) 1 2)))
! (replace-match "" t nil nil n)
! (goto-char (match-end n))))
! (unless (string= glasses-separator glasses-original-separator)
! (goto-char (point-min))
! (while (re-search-forward (format "[a-zA-Z0-9]\\(%s+\\)[a-zA-Z0-9]"
! separator)
! nil t)
! (replace-match glasses-original-separator nil nil nil 1)
! (goto-char (match-beginning 1)))))
(when glasses-separate-parentheses-p
(goto-char (point-min))
(while (re-search-forward "[a-zA-Z]_*\\( \\)\(" nil t)
! (unless (glasses-parenthesis-exception-p (point-at-bol) (1+
(match-end 1)))
! (replace-match "" t nil nil 1)))))))
;; nil must be returned to allow use in write file hooks
nil)
Index: lisp/ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.10303
diff -c -0 -r1.10303 ChangeLog
*** lisp/ChangeLog 12 Nov 2006 19:58:10 -0000 1.10303
--- lisp/ChangeLog 17 Nov 2006 01:15:47 -0000
***************
*** 0 ****
--- 1,11 ----
+ 2006-11-17 Michaël Cadilhac <address@hidden>
+
+ * progmodes/glasses.el (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.
+
TIA!
--
/!\ My mail address changed, please update your files accordingly.
| Michaël `Micha' Cadilhac | La culture c'est comme la confiture, |
| Epita/LRDE Promo 2007 | c'est meilleur avec du pain. |
| http://michael.cadilhac.name | -- MOI59 |
`--JID: address@hidden' - --'
pgp5nZN2CJa5X.pgp
Description: PGP signature
- Glasses.el and C bug.,
Michaël Cadilhac <=