aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/cap-words.el98
1 files changed, 98 insertions, 0 deletions
diff --git a/lisp/progmodes/cap-words.el b/lisp/progmodes/cap-words.el
new file mode 100644
index 00000000000..94e865db62b
--- /dev/null
+++ b/lisp/progmodes/cap-words.el
@@ -0,0 +1,98 @@
1;;; cap-words.el --- minor mode for motion in CapitalizedWordIdentifiers
2
3;; Copyright (C) 2002-2015 Free Software Foundation, Inc.
4
5;; Author: Dave Love <fx@gnu.org>
6;; Keywords: languages
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software: you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
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
21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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-find-word-boundary (pos limit)
37 "Function for use in `find-word-boundary-function-table'.
38Looks 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
54(defconst capitalized-find-word-boundary-function-table
55 (let ((tab (make-char-table nil)))
56 (set-char-table-range tab t #'capitalized-find-word-boundary)
57 tab)
58 "Assigned to `find-word-boundary-function-table' in Capitalized Words mode.")
59
60;;;###autoload
61(define-minor-mode capitalized-words-mode
62 "Toggle Capitalized Words mode.
63With a prefix argument ARG, enable Capitalized Words mode if ARG
64is positive, and disable it otherwise. If called from Lisp,
65enable the mode if ARG is omitted or nil.
66
67Capitalized Words mode is a buffer-local minor mode. When
68enabled, a word boundary occurs immediately before an uppercase
69letter in a symbol. This is in addition to all the normal
70boundaries given by the syntax and category tables. There is no
71restriction to ASCII.
72
73E.g. the beginning of words in the following identifier are as marked:
74
75 capitalizedWorDD
76 ^ ^ ^^
77
78Note that these word boundaries only apply for word motion and
79marking commands such as \\[forward-word]. This mode does not affect word
80boundaries found by regexp matching (`\\>', `\\w' &c).
81
82This style of identifiers is common in environments like Java ones,
83where underscores aren't trendy enough. Capitalization rules are
84sometimes part of the language, e.g. Haskell, which may thus encourage
85such a style. It is appropriate to add `capitalized-words-mode' to
86the mode hook for programming language modes in which you encounter
87variables like this, e.g. `java-mode-hook'. It's unlikely to cause
88trouble if such identifiers aren't used.
89
90See also `glasses-mode' and `studlify-word'.
91Obsoletes `c-forward-into-nomenclature'."
92 nil " Caps" nil :group 'programming
93 (set (make-local-variable 'find-word-boundary-function-table)
94 capitalized-find-word-boundary-function-table))
95
96(provide 'cap-words)
97
98;;; cap-words.el ends here