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