Commit | Line | Data |
---|---|---|
4a6a3d18 | 1 | ;;; cap-words.el --- minor mode for motion in CapitalizedWordIdentifiers |
f7ab7a26 DL |
2 | |
3 | ;; Copyright (C) 2002 Free Software Foundation, Inc. | |
4 | ||
5 | ;; Author: Dave Love <fx@gnu.org> | |
6 | ;; Keywords: languages | |
7 | ||
8 | ;; This file is free software; you can redistribute it and/or modify | |
9 | ;; it under the terms of the GNU General Public License as published by | |
10 | ;; the Free Software Foundation; either version 2, or (at your option) | |
11 | ;; any later version. | |
12 | ||
13 | ;; This file is distributed in the hope that it will be useful, | |
14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | ;; GNU General Public License for more details. | |
17 | ||
18 | ;; You should have received a copy of the GNU General Public License | |
19 | ;; along with GNU Emacs; see the file COPYING. If not, write to | |
20 | ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | ;; Boston, MA 02111-1307, USA. | |
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 | ||
36 | (defun capitalized-next-word-boundary (pos limit) | |
37 | "Function for use in `next-word-boundary-function-table'. | |
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 | ||
53 | (defconst capitalized-next-word-boundary-function-table | |
54 | (let ((tab (make-char-table nil))) | |
55 | (set-char-table-range tab t #'capitalized-next-word-boundary) | |
56 | tab) | |
57 | "Assigned to `next-word-boundary-function-table' in Capitalized Words mode.") | |
58 | ||
6eff8ddf | 59 | ;;;###autoload |
f7ab7a26 DL |
60 | (define-minor-mode capitalized-words-mode |
61 | "Toggle Capitalized- Words mode. | |
62 | ||
63 | In this minor mode, a word boundary occurs immediately before an | |
64 | uppercase letter in a symbol. This is in addition to all the normal | |
65 | boundaries given by the syntax and category tables. There is no | |
66 | restriction to ASCII. | |
67 | ||
68 | E.g. the beginning of words in the following identifier are as marked: | |
69 | ||
70 | capitalizedWorDD | |
71 | ^ ^ ^^ | |
72 | ||
73 | Note that these word boundaries only apply for word motion and | |
74 | marking commands such as \\[forward-word]. This mode does not affect word | |
75 | boundaries in found by regexp matching (`\\>', `\\w' &c). | |
76 | ||
77 | This style of identifiers is common in environments like Java ones, | |
78 | where underscores aren't trendy enough. Capitalization rules are | |
6eff8ddf DL |
79 | sometimes part of the language, e.g. Haskell, which may thus encourage |
80 | such a style. It is appropriate to add `capitalized-words-mode' to | |
81 | the mode hook for programming langauge modes in which you encounter | |
82 | variables like this, e.g. `java-mode-hook'. It's unlikely to cause | |
83 | trouble if such identifiers aren't used. | |
f7ab7a26 DL |
84 | |
85 | See also `glasses-mode' and `studlify-word'. | |
86 | Obsoletes `c-forward-into-nomenclature'." | |
87 | nil " Caps" nil :group 'programming | |
88 | (set (make-local-variable 'next-word-boundary-function-table) | |
89 | capitalized-next-word-boundary-function-table)) | |
90 | ||
91 | (provide 'cap-words) | |
fbaf0946 MB |
92 | |
93 | ;;; arch-tag: 46513b64-fe5a-4c0b-902c-ed235c22975f | |
f7ab7a26 | 94 | ;;; cap-words.el ends here |