From: michael@cadilhac.name (Michaël Cadilhac)
Subject: Glasses.el and C bug.
Date: Fri, 17 Nov 2006 02:25:07 +0100 [thread overview]
Message-ID: <878xiac1ak.fsf@lrde.org> (raw)
[-- Attachment #1.1.1: Type: text/plain, Size: 608 bytes --]
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).
[-- Attachment #1.1.2: glasses.patch --]
[-- Type: text/x-patch, Size: 5774 bytes --]
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 <michael.cadilhac@lrde.org>
+
+ * 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.
+
[-- Attachment #1.1.3: Type: text/plain, Size: 407 bytes --]
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: michael.cadilhac@gmail.com--' - --'
[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]
[-- Attachment #2: Type: text/plain, Size: 142 bytes --]
_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel
next reply other threads:[~2006-11-17 1:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-17 1:25 Michaël Cadilhac [this message]
2006-11-19 7:59 ` Glasses.el and C bug Richard Stallman
2006-11-19 16:34 ` Michaël Cadilhac
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878xiac1ak.fsf@lrde.org \
--to=michael@cadilhac.name \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).