]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/glasses.el
fix typos
[gnu-emacs] / lisp / progmodes / glasses.el
index 9a4c18e19df911cf9a4f17ccb65f07e3cfd571bf..dea40b8db19da531c7697f9bc502b339c16a34a0 100644 (file)
@@ -1,9 +1,9 @@
 ;;; glasses.el --- make cantReadThis readable
 
-;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
 
-;; Author: Milan Zamazal <pdm@freesoft.cz>
-;; Maintainer: Milan Zamazal <pdm@freesoft.cz>
+;; Author: Milan Zamazal <pdm@zamazal.org>
+;; Maintainer: Milan Zamazal <pdm@zamazal.org>
 ;; Keywords: tools
 
 ;; This file is part of GNU Emacs.
@@ -62,6 +62,7 @@
 
 (defgroup glasses nil
   "Make unreadable code likeThis(one) readable."
+  :version "21.1"
   :group 'tools)
 
 
@@ -128,7 +129,7 @@ separators too."
 (defun glasses-custom-set (symbol value)
   "Set value of the variable SYMBOL to VALUE and update overlay categories.
 Used in :set parameter of some customized glasses variables."
-  (set symbol value)
+  (set-default symbol value)
   (glasses-set-overlay-properties))
 
 
@@ -186,6 +187,8 @@ CATEGORY is the overlay category.  If it is nil, use the `glasses' category."
                 (o (glasses-make-overlay (match-beginning n) (match-end n))))
            (goto-char (match-beginning n))
            (when (and glasses-uncapitalize-p
+                      (save-match-data
+                        (looking-at "[A-Z]\\($\\|[^A-Z]\\)"))
                       (save-excursion
                         (save-match-data
                           (re-search-backward "\\<.")
@@ -195,7 +198,7 @@ CATEGORY is the overlay category.  If it is nil, use the `glasses' category."
        ;; Parentheses
        (when glasses-separate-parentheses-p
          (goto-char beg)
-         (while (re-search-forward "[a-zA-Z]\\(\(\\)" end t)
+         (while (re-search-forward "[a-zA-Z]_*\\(\(\\)" end t)
            (glasses-make-overlay (match-beginning 1) (match-end 1)
                                  'glasses-parenthesis)))))))
 
@@ -226,13 +229,13 @@ recognized according to the current value of the variable `glasses-separator'."
            (goto-char (match-end n))))
        (when glasses-separate-parentheses-p
          (goto-char (point-min))
-         (while (re-search-forward "[a-zA-Z]\\( \\)\(" nil t)
+         (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)
 
 
-(defun glasses-change (beg end old-len)
+(defun glasses-change (beg end &optional old-len)
   "After-change function updating glass overlays."
   (let ((beg-line (save-excursion (goto-char beg) (line-beginning-position)))
        (end-line (save-excursion (goto-char end) (line-end-position))))
@@ -243,40 +246,26 @@ recognized according to the current value of the variable `glasses-separator'."
 ;;; Minor mode definition
 
 
-(defvar glasses-mode nil
-  "Mode variable for `glasses-mode'.")
-(make-variable-buffer-local 'glasses-mode)
-
-(add-to-list 'minor-mode-alist '(glasses-mode " o^o"))
-
-
 ;;;###autoload
-(defun glasses-mode (arg)
+(define-minor-mode glasses-mode
   "Minor mode for making identifiers likeThis readable.
 When this mode is active, it tries to add virtual separators (like underscores)
 at places they belong to."
-  (interactive "P")
-  (let ((new-flag (if (null arg)
-                      (not glasses-mode)
-                   (> (prefix-numeric-value arg) 0))))
-    (unless (eq new-flag glasses-mode)
-      (save-excursion
-       (save-restriction
-         (widen)
-         ;; We erase the all overlays anyway, to avoid dual sight in some
-         ;; circumstances
-         (glasses-make-unreadable (point-min) (point-max))
-         (if new-flag
-             (progn
-               (glasses-make-readable (point-min) (point-max))
-               (make-local-hook 'after-change-functions)
-               (add-hook 'after-change-functions 'glasses-change nil t)
-               (add-hook 'local-write-file-hooks
-                         'glasses-convert-to-unreadable nil t))
-           (remove-hook 'after-change-functions 'glasses-change t)
-           (remove-hook 'local-write-file-hooks
-                        'glasses-convert-to-unreadable t))))
-      (setq glasses-mode new-flag))))
+  nil " o^o" nil
+  (save-excursion
+    (save-restriction
+      (widen)
+      ;; We erase all the overlays anyway, to avoid dual sight in some
+      ;; circumstances
+      (glasses-make-unreadable (point-min) (point-max))
+      (if glasses-mode
+         (progn
+           (jit-lock-register 'glasses-change)
+           (add-hook 'local-write-file-hooks
+                     'glasses-convert-to-unreadable nil t))
+       (jit-lock-unregister 'glasses-change)
+       (remove-hook 'local-write-file-hooks
+                    'glasses-convert-to-unreadable t)))))
 
 
 ;;; Announce
@@ -284,4 +273,5 @@ at places they belong to."
 (provide 'glasses)
 
 
+;;; arch-tag: a3515167-c89e-484f-90a1-d85143e52b12
 ;;; glasses.el ends here