diff options
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/progmodes/glasses.el | 232 | ||||
| -rw-r--r-- | man/misc.texi | 5 |
3 files changed, 241 insertions, 1 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 00ffed88f6a..0cbb0fbf6af 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,10 @@ | |||
| 1 | 2000-01-28 Gerd Moellmann <gerd@gnu.org> | 1 | 2000-01-28 Gerd Moellmann <gerd@gnu.org> |
| 2 | 2 | ||
| 3 | * sort.el (sort-numeric-base): New option. | ||
| 4 | (sort-numeric-fields): If number starts with `0' or `0[xX[', | ||
| 5 | interpret it as octal or hexadecimal. Use sort-numeric-base | ||
| 6 | as default base. | ||
| 7 | |||
| 3 | * progmodes/glasses.el: New file. | 8 | * progmodes/glasses.el: New file. |
| 4 | 9 | ||
| 5 | 2000-01-27 Gerd Moellmann <gerd@gnu.org> | 10 | 2000-01-27 Gerd Moellmann <gerd@gnu.org> |
diff --git a/lisp/progmodes/glasses.el b/lisp/progmodes/glasses.el new file mode 100644 index 00000000000..ee66545b702 --- /dev/null +++ b/lisp/progmodes/glasses.el | |||
| @@ -0,0 +1,232 @@ | |||
| 1 | ;;; glasses.el --- make cantReadThis readable | ||
| 2 | |||
| 3 | ;; Copyright (C) 1999 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Milan Zamazal <pdm@freesoft.cz> | ||
| 6 | ;; Maintainer: Milan Zamazal <pdm@freesoft.cz> | ||
| 7 | ;; Keywords: tools | ||
| 8 | |||
| 9 | ;; This file is part of GNU Emacs. | ||
| 10 | |||
| 11 | ;; GNU Emacs is free software; you can redistribute it and/or modify | ||
| 12 | ;; it under the terms of the GNU General Public License as published by | ||
| 13 | ;; the Free Software Foundation; either version 2, or (at your option) | ||
| 14 | ;; any later version. | ||
| 15 | |||
| 16 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 19 | ;; GNU General Public License for more details. | ||
| 20 | |||
| 21 | ;; You should have received a copy of the GNU General Public License | ||
| 22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | ||
| 23 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
| 24 | ;; Boston, MA 02111-1307, USA. | ||
| 25 | |||
| 26 | ;;; Commentary: | ||
| 27 | |||
| 28 | ;; This file defines a minor mode for making unreadableIdentifiersLikeThis | ||
| 29 | ;; readable. In some environments, for instance Java, it is common to use such | ||
| 30 | ;; unreadable identifiers. It is not good to use underscores in identifiers of | ||
| 31 | ;; your own project in such an environment to make your sources more readable, | ||
| 32 | ;; since it introduces undesirable confusion, which is worse than the | ||
| 33 | ;; unreadability. Fortunately, you use Emacs for the subproject, so the | ||
| 34 | ;; problem can be solved some way. | ||
| 35 | ;; | ||
| 36 | ;; This file defines the `glasses-mode' minor mode, which displays underscores | ||
| 37 | ;; between all the pairs of lower and upper English letters. (This only | ||
| 38 | ;; displays underscores, the text is not changed actually.) Alternatively, you | ||
| 39 | ;; can say you want the capitals in some given face (e.g. bold). | ||
| 40 | ;; | ||
| 41 | ;; The mode does something usable, though not perfect. Improvement suggestions | ||
| 42 | ;; from Emacs experts are welcome. | ||
| 43 | ;; | ||
| 44 | ;; If you like in-identifier separators different from underscores, change the | ||
| 45 | ;; value of the variable `glasses-separator' appropriately. See also the | ||
| 46 | ;; variables `glasses-face' and `glasses-convert-on-write-p'. You can also use | ||
| 47 | ;; the command `M-x customize-group RET glasses RET'. | ||
| 48 | ;; | ||
| 49 | ;; If you set any of the variables `glasses-separator' or `glasses-face' after | ||
| 50 | ;; glasses.el is loaded and in a different way than through customize, you | ||
| 51 | ;; should call the function `glasses-set-overlay-properties' afterwards. | ||
| 52 | |||
| 53 | ;;; Code: | ||
| 54 | |||
| 55 | |||
| 56 | (eval-when-compile | ||
| 57 | (require 'cl)) | ||
| 58 | |||
| 59 | |||
| 60 | ;;; User variables | ||
| 61 | |||
| 62 | |||
| 63 | (defgroup glasses nil | ||
| 64 | "Make unreadable identifiers likeThis readable." | ||
| 65 | :group 'tools) | ||
| 66 | |||
| 67 | |||
| 68 | (defcustom glasses-separator "_" | ||
| 69 | "*String to be displayed as a visual separator in unreadable identifiers." | ||
| 70 | :group 'glasses | ||
| 71 | :type 'string | ||
| 72 | :set 'glasses-custom-set | ||
| 73 | :initialize 'custom-initialize-default) | ||
| 74 | |||
| 75 | |||
| 76 | (defcustom glasses-face nil | ||
| 77 | "*Face to be put on capitals of an identifier looked through glasses. | ||
| 78 | If it is nil, no face is placed at the capitalized letter. | ||
| 79 | |||
| 80 | For example, you can set `glasses-separator' to an empty string and | ||
| 81 | `glasses-face' to `bold'. Then unreadable identifiers will have no separators, | ||
| 82 | but will have their capitals in bold." | ||
| 83 | :group 'glasses | ||
| 84 | :type 'symbol | ||
| 85 | :set 'glasses-custom-set | ||
| 86 | :initialize 'custom-initialize-default) | ||
| 87 | |||
| 88 | |||
| 89 | (defcustom glasses-convert-on-write-p nil | ||
| 90 | "*If non-nil, remove separators when writing glasses buffer to a file. | ||
| 91 | If you are confused by glasses so much, that you write the separators into code | ||
| 92 | during coding, set this variable to t. The separators will be removed on each | ||
| 93 | file write then. | ||
| 94 | |||
| 95 | Note the removal action does not try to be much clever, so it can remove real | ||
| 96 | separators too." | ||
| 97 | :group 'glasses | ||
| 98 | :type 'boolean) | ||
| 99 | |||
| 100 | |||
| 101 | (defun glasses-custom-set (symbol value) | ||
| 102 | "Set value of the variable SYMBOL to VALUE and update overlay categories. | ||
| 103 | Used in :set parameter of some customized glasses variables." | ||
| 104 | (set symbol value) | ||
| 105 | (glasses-set-overlay-properties)) | ||
| 106 | |||
| 107 | |||
| 108 | ;;; Utility functions | ||
| 109 | |||
| 110 | |||
| 111 | (defun glasses-set-overlay-properties () | ||
| 112 | "Set properties of glasses overlays. | ||
| 113 | Consider current setting of user variables." | ||
| 114 | ;; In-identifier overlay | ||
| 115 | (put 'glasses 'evaporate t) | ||
| 116 | (put 'glasses 'before-string glasses-separator) | ||
| 117 | (put 'glasses 'face glasses-face) | ||
| 118 | ;; Beg-identifier overlay | ||
| 119 | (put 'glasses-init 'evaporate t) | ||
| 120 | (put 'glasses-init 'face glasses-face)) | ||
| 121 | |||
| 122 | (glasses-set-overlay-properties) | ||
| 123 | |||
| 124 | |||
| 125 | (defun glasses-overlay-p (overlay) | ||
| 126 | "Return whether OVERLAY is an overlay of glasses mode." | ||
| 127 | (memq (overlay-get overlay 'category) '(glasses glasses-init))) | ||
| 128 | |||
| 129 | |||
| 130 | (defun glasses-make-overlay (beg end &optional init) | ||
| 131 | "Create readability overlay over the region from BEG to END. | ||
| 132 | If INIT is non-nil, put `glasses-init' overlay there." | ||
| 133 | (let ((overlay (make-overlay beg end))) | ||
| 134 | (overlay-put overlay 'category (if init 'glasses-init 'glasses)))) | ||
| 135 | |||
| 136 | |||
| 137 | (defun glasses-make-readable (beg end) | ||
| 138 | "Make identifiers in the region from BEG to END readable." | ||
| 139 | (let ((case-fold-search nil)) | ||
| 140 | (save-excursion | ||
| 141 | (save-match-data | ||
| 142 | ;; Face only | ||
| 143 | (goto-char beg) | ||
| 144 | (while (re-search-forward | ||
| 145 | "\\<\\([A-Z]\\)[a-zA-Z]*\\([a-z][A-Z]\\|[A-Z][a-z]\\)" | ||
| 146 | end t) | ||
| 147 | (glasses-make-overlay (match-beginning 1) (match-end 1) t)) | ||
| 148 | (goto-char beg) | ||
| 149 | ;; Face + separator | ||
| 150 | (while (re-search-forward "[a-z]\\([A-Z]\\)\\|[A-Z]\\([A-Z]\\)[a-z]" | ||
| 151 | end t) | ||
| 152 | (let ((n (if (match-string 1) 1 2))) | ||
| 153 | (glasses-make-overlay (match-beginning n) (match-end n)) | ||
| 154 | (goto-char (match-beginning n)))))))) | ||
| 155 | |||
| 156 | |||
| 157 | (defun glasses-make-unreadable (beg end) | ||
| 158 | "Return identifiers in the region from BEG to END to their unreadable state." | ||
| 159 | (dolist (o (overlays-in beg end)) | ||
| 160 | (when (glasses-overlay-p o) | ||
| 161 | (delete-overlay o)))) | ||
| 162 | |||
| 163 | |||
| 164 | (defun glasses-convert-to-unreadable () | ||
| 165 | "Convert current buffer to unreadable identifiers and return nil. | ||
| 166 | This function modifies buffer contents, it removes all the separators, | ||
| 167 | recognized according to the current value of the variable `glasses-separator'." | ||
| 168 | (when (and glasses-convert-on-write-p | ||
| 169 | (not (string= glasses-separator ""))) | ||
| 170 | (let ((case-fold-search nil)) | ||
| 171 | (save-excursion | ||
| 172 | (goto-char (point-min)) | ||
| 173 | (while (re-search-forward | ||
| 174 | "[a-z]\\(_\\)[A-Z]\\|[A-Z]\\(_\\)[A-Z][a-z]" nil t) | ||
| 175 | (let ((n (if (match-string 1) 1 2))) | ||
| 176 | (replace-match "" t nil nil n) | ||
| 177 | (goto-char (match-end n))))))) | ||
| 178 | ;; nil must be returned to allow use in write file hooks | ||
| 179 | nil) | ||
| 180 | |||
| 181 | |||
| 182 | (defun glasses-change (beg end old-len) | ||
| 183 | "After-change function updating glass overlays." | ||
| 184 | (let ((beg-line (save-excursion (goto-char beg) (line-beginning-position))) | ||
| 185 | (end-line (save-excursion (goto-char end) (line-end-position)))) | ||
| 186 | (glasses-make-unreadable beg-line end-line) | ||
| 187 | (glasses-make-readable beg-line end-line))) | ||
| 188 | |||
| 189 | |||
| 190 | ;;; Minor mode definition | ||
| 191 | |||
| 192 | |||
| 193 | (defvar glasses-mode nil | ||
| 194 | "Mode variable for `glasses-mode'.") | ||
| 195 | (make-variable-buffer-local 'glasses-mode) | ||
| 196 | |||
| 197 | (add-to-list 'minor-mode-alist '(glasses-mode " o^o")) | ||
| 198 | |||
| 199 | |||
| 200 | ;;;###autoload | ||
| 201 | (defun glasses-mode (arg) | ||
| 202 | "Minor mode for making identifiers likeThis readable. | ||
| 203 | When this mode is active, it tries to add virtual separators (like underscores) | ||
| 204 | at places they belong to." | ||
| 205 | (interactive "P") | ||
| 206 | (let ((new-flag (if (null arg) | ||
| 207 | (not glasses-mode) | ||
| 208 | (> (prefix-numeric-value arg) 0)))) | ||
| 209 | (unless (eq new-flag glasses-mode) | ||
| 210 | (save-excursion | ||
| 211 | (save-restriction | ||
| 212 | (widen) | ||
| 213 | (if new-flag | ||
| 214 | (progn | ||
| 215 | (glasses-make-readable (point-min) (point-max)) | ||
| 216 | (make-local-hook 'after-change-functions) | ||
| 217 | (add-hook 'after-change-functions 'glasses-change nil t) | ||
| 218 | (add-hook 'local-write-file-hooks | ||
| 219 | 'glasses-convert-to-unreadable nil t)) | ||
| 220 | (glasses-make-unreadable (point-min) (point-max)) | ||
| 221 | (remove-hook 'after-change-functions 'glasses-change t) | ||
| 222 | (remove-hook 'local-write-file-hooks | ||
| 223 | 'glasses-convert-to-unreadable t)))) | ||
| 224 | (setq glasses-mode new-flag)))) | ||
| 225 | |||
| 226 | |||
| 227 | ;;; Announce | ||
| 228 | |||
| 229 | (provide 'glasses) | ||
| 230 | |||
| 231 | |||
| 232 | ;;; glasses.el ends here | ||
diff --git a/man/misc.texi b/man/misc.texi index 28e035bfadd..249a2bed23d 100644 --- a/man/misc.texi +++ b/man/misc.texi | |||
| @@ -1414,6 +1414,7 @@ record as the sort key. | |||
| 1414 | @findex sort-pages | 1414 | @findex sort-pages |
| 1415 | @findex sort-fields | 1415 | @findex sort-fields |
| 1416 | @findex sort-numeric-fields | 1416 | @findex sort-numeric-fields |
| 1417 | @vindex sort-numeric-base | ||
| 1417 | @table @kbd | 1418 | @table @kbd |
| 1418 | @item M-x sort-lines | 1419 | @item M-x sort-lines |
| 1419 | Divide the region into lines, and sort by comparing the entire | 1420 | Divide the region into lines, and sort by comparing the entire |
| @@ -1446,7 +1447,9 @@ keep same relative order that they had in the original buffer. | |||
| 1446 | Like @kbd{M-x sort-fields} except the specified field is converted | 1447 | Like @kbd{M-x sort-fields} except the specified field is converted |
| 1447 | to an integer for each line, and the numbers are compared. @samp{10} | 1448 | to an integer for each line, and the numbers are compared. @samp{10} |
| 1448 | comes before @samp{2} when considered as text, but after it when | 1449 | comes before @samp{2} when considered as text, but after it when |
| 1449 | considered as a number. | 1450 | considered as a number. By default, numbers are interpreted according |
| 1451 | to @code{sort-numeric-base}, but numbers beginning with @samp{0x} or | ||
| 1452 | @samp{0} are interpreted as hexadecimal and octal, respectively. | ||
| 1450 | 1453 | ||
| 1451 | @item M-x sort-columns | 1454 | @item M-x sort-columns |
| 1452 | Like @kbd{M-x sort-fields} except that the text within each line | 1455 | Like @kbd{M-x sort-fields} except that the text within each line |