unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Glasses.el and C bug.
@ 2006-11-17  1:25 Michaël Cadilhac
  2006-11-19  7:59 ` Richard Stallman
  0 siblings, 1 reply; 3+ messages in thread
From: Michaël Cadilhac @ 2006-11-17  1:25 UTC (permalink / 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Glasses.el and C bug.
  2006-11-17  1:25 Glasses.el and C bug Michaël Cadilhac
@ 2006-11-19  7:59 ` Richard Stallman
  2006-11-19 16:34   ` Michaël Cadilhac
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Stallman @ 2006-11-19  7:59 UTC (permalink / raw)
  Cc: emacs-devel

Would you please install your patch?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Glasses.el and C bug.
  2006-11-19  7:59 ` Richard Stallman
@ 2006-11-19 16:34   ` Michaël Cadilhac
  0 siblings, 0 replies; 3+ messages in thread
From: Michaël Cadilhac @ 2006-11-19 16:34 UTC (permalink / raw)
  Cc: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 529 bytes --]

Richard Stallman <rms@gnu.org> writes:

> Would you please install your patch?

Would someone please do?  I don't have commit permissions.
(Message-ID of the patch: <878xiac1ak.fsf@lrde.org>)

-- 
 |      Michaël `Micha' Cadilhac     |  ... And I talked about KVim.          |
 |         Epita/LRDE Promo 2007     |   "I can't tell if I am more sorry     |
 |  http://michael.cadilhac.name     |        for vim or for KDE."            |
 `--JID: michael.cadilhac@gmail.com--'          -- RMS                   -  --'

[-- 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-11-19 16:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-17  1:25 Glasses.el and C bug Michaël Cadilhac
2006-11-19  7:59 ` Richard Stallman
2006-11-19 16:34   ` Michaël Cadilhac

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).