]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/glasses.el
(gud-stop-subjob): Using jdb, suspend threads
[gnu-emacs] / lisp / progmodes / glasses.el
index a8d2d8b8fe1f3a018b81bf92a89574c16a94d300..8c3103b6ba475b1089c5b27feb66fd37aa33db52 100644 (file)
@@ -1,6 +1,7 @@
 ;;; glasses.el --- make cantReadThis readable
 
-;; Copyright (C) 1999, 2000, 2001, 2005, 2006 Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+;;   Free Software Foundation, Inc.
 
 ;; Author: Milan Zamazal <pdm@zamazal.org>
 ;; Maintainer: Milan Zamazal <pdm@zamazal.org>
@@ -8,10 +9,10 @@
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,9 +20,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -67,7 +66,7 @@
 
 
 (defcustom glasses-separator "_"
-  "*String to be displayed as a visual separator in identifiers.
+  "String to be displayed as a visual separator in identifiers.
 It is used both for adding missing separators and for replacing separators
 defined by `glasses-original-separator'.  If you don't want to add missing
 separators, set `glasses-separator' to an empty string.  If you don't want to
@@ -93,7 +92,7 @@ performed."
 
 
 (defcustom glasses-face nil
-  "*Face to be put on capitals of an identifier looked through glasses.
+  "Face to be put on capitals of an identifier looked through glasses.
 If it is nil, no face is placed at the capitalized letter.
 
 For example, you can set `glasses-separator' to an empty string and
@@ -106,13 +105,20 @@ but will have their capitals in bold."
 
 
 (defcustom glasses-separate-parentheses-p t
-  "*If non-nil, ensure space between an identifier and an opening parenthesis."
+  "If non-nil, ensure space between an identifier and an opening parenthesis."
   :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.
+  "If non-nil, downcase embedded capital letters in identifiers.
 Only identifiers starting with lower case letters are affected, letters inside
 other identifiers are unchanged."
   :group 'glasses
@@ -122,7 +128,7 @@ other identifiers are unchanged."
 
 
 (defcustom glasses-uncapitalize-regexp "[a-z]"
-  "*Regexp matching beginnings of words to be uncapitalized.
+  "Regexp matching beginnings of words to be uncapitalized.
 Only words starting with this regexp are uncapitalized.
 The regexp is case sensitive.
 It has any effect only when `glasses-uncapitalize-p' is non-nil."
@@ -133,7 +139,7 @@ It has any effect only when `glasses-uncapitalize-p' is non-nil."
 
 
 (defcustom glasses-convert-on-write-p nil
-  "*If non-nil, remove separators when writing glasses buffer to a file.
+  "If non-nil, remove separators when writing glasses buffer to a file.
 If you are confused by glasses so much, that you write the separators into code
 during coding, set this variable to t.  The separators will be removed on each
 file write then.
@@ -153,6 +159,14 @@ Used in :set parameter of some customized glasses variables."
 
 ;;; 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,8 +246,9 @@ CATEGORY is the overlay category.  If it is nil, use the `glasses' category."
        (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)))))))
+           (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,30 +262,31 @@ CATEGORY is the overlay category.  If it is nil, use the `glasses' category."
   "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 "")))
+  (when glasses-convert-on-write-p
     (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)
+       (unless (string= glasses-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))))
+         (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))))))
+           (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)
 
@@ -313,5 +329,5 @@ at places they belong to."
 (provide 'glasses)
 
 
-;;; arch-tag: a3515167-c89e-484f-90a1-d85143e52b12
+;; arch-tag: a3515167-c89e-484f-90a1-d85143e52b12
 ;;; glasses.el ends here