Commit | Line | Data |
---|---|---|
4a6a3d18 | 1 | ;;; cap-words.el --- minor mode for motion in CapitalizedWordIdentifiers |
f7ab7a26 | 2 | |
ab422c4d | 3 | ;; Copyright (C) 2002-2013 Free Software Foundation, Inc. |
f7ab7a26 DL |
4 | |
5 | ;; Author: Dave Love <fx@gnu.org> | |
6 | ;; Keywords: languages | |
7 | ||
b1fc2b50 GM |
8 | ;; This file is part of GNU Emacs. |
9 | ||
10 | ;; GNU Emacs is free software: you can redistribute it and/or modify | |
f7ab7a26 | 11 | ;; it under the terms of the GNU General Public License as published by |
b1fc2b50 GM |
12 | ;; the Free Software Foundation, either version 3 of the License, or |
13 | ;; (at your option) any later version. | |
f7ab7a26 | 14 | |
b1fc2b50 | 15 | ;; GNU Emacs is distributed in the hope that it will be useful, |
f7ab7a26 DL |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;; GNU General Public License for more details. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
b1fc2b50 | 21 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
f7ab7a26 DL |
22 | |
23 | ;;; Commentary: | |
24 | ||
25 | ;; Provides Capitalized Words minor mode for word movement in | |
26 | ;; identifiers CapitalizedLikeThis. | |
27 | ||
28 | ;; Note that the same effect could be obtained by frobbing the | |
29 | ;; category of upper case characters to produce word boundaries, but | |
30 | ;; the necessary processing isn't done for ASCII characters. | |
31 | ||
32 | ;; Fixme: This doesn't work properly for mouse double clicks. | |
33 | ||
34 | ;;; Code: | |
35 | ||
d4b5f7d7 GM |
36 | (defun capitalized-find-word-boundary (pos limit) |
37 | "Function for use in `find-word-boundary-function-table'. | |
f7ab7a26 DL |
38 | Looks for word boundaries before capitals." |
39 | (save-excursion | |
40 | (goto-char pos) | |
41 | (let (case-fold-search) | |
42 | (if (<= pos limit) | |
43 | ;; Fixme: Are these regexps the best? | |
44 | (or (and (re-search-forward "\\=.\\w*[[:upper:]]" | |
45 | limit t) | |
46 | (progn (backward-char) | |
47 | t)) | |
48 | (re-search-forward "\\>" limit t)) | |
49 | (or (re-search-backward "[[:upper:]]\\w*\\=" limit t) | |
50 | (re-search-backward "\\<" limit t)))) | |
51 | (point))) | |
52 | ||
d4b5f7d7 GM |
53 | |
54 | (defconst capitalized-find-word-boundary-function-table | |
f7ab7a26 | 55 | (let ((tab (make-char-table nil))) |
d4b5f7d7 | 56 | (set-char-table-range tab t #'capitalized-find-word-boundary) |
f7ab7a26 | 57 | tab) |
d4b5f7d7 | 58 | "Assigned to `find-word-boundary-function-table' in Capitalized Words mode.") |
f7ab7a26 | 59 | |
6eff8ddf | 60 | ;;;###autoload |
f7ab7a26 | 61 | (define-minor-mode capitalized-words-mode |
f05cde18 | 62 | "Toggle Capitalized Words mode. |
ac6c8639 CY |
63 | With a prefix argument ARG, enable Capitalized Words mode if ARG |
64 | is positive, and disable it otherwise. If called from Lisp, | |
65 | enable the mode if ARG is omitted or nil. | |
f7ab7a26 | 66 | |
ac6c8639 CY |
67 | Capitalized Words mode is a buffer-local minor mode. When |
68 | enabled, a word boundary occurs immediately before an uppercase | |
69 | letter in a symbol. This is in addition to all the normal | |
f7ab7a26 DL |
70 | boundaries given by the syntax and category tables. There is no |
71 | restriction to ASCII. | |
72 | ||
73 | E.g. the beginning of words in the following identifier are as marked: | |
74 | ||
75 | capitalizedWorDD | |
76 | ^ ^ ^^ | |
77 | ||
78 | Note that these word boundaries only apply for word motion and | |
79 | marking commands such as \\[forward-word]. This mode does not affect word | |
f05cde18 | 80 | boundaries found by regexp matching (`\\>', `\\w' &c). |
f7ab7a26 DL |
81 | |
82 | This style of identifiers is common in environments like Java ones, | |
83 | where underscores aren't trendy enough. Capitalization rules are | |
6eff8ddf DL |
84 | sometimes part of the language, e.g. Haskell, which may thus encourage |
85 | such a style. It is appropriate to add `capitalized-words-mode' to | |
f05cde18 | 86 | the mode hook for programming language modes in which you encounter |
6eff8ddf DL |
87 | variables like this, e.g. `java-mode-hook'. It's unlikely to cause |
88 | trouble if such identifiers aren't used. | |
f7ab7a26 DL |
89 | |
90 | See also `glasses-mode' and `studlify-word'. | |
91 | Obsoletes `c-forward-into-nomenclature'." | |
92 | nil " Caps" nil :group 'programming | |
d4b5f7d7 GM |
93 | (set (make-local-variable 'find-word-boundary-function-table) |
94 | capitalized-find-word-boundary-function-table)) | |
f7ab7a26 DL |
95 | |
96 | (provide 'cap-words) | |
fbaf0946 | 97 | |
f7ab7a26 | 98 | ;;; cap-words.el ends here |