89311
|
1 ;;; cap-words.el --- minor mode for motion in CapsitalizedWordIdentifiers
|
|
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
|
|
59 (define-minor-mode capitalized-words-mode
|
|
60 "Toggle Capitalized- Words mode.
|
|
61
|
|
62 In this minor mode, a word boundary occurs immediately before an
|
|
63 uppercase letter in a symbol. This is in addition to all the normal
|
|
64 boundaries given by the syntax and category tables. There is no
|
|
65 restriction to ASCII.
|
|
66
|
|
67 E.g. the beginning of words in the following identifier are as marked:
|
|
68
|
|
69 capitalizedWorDD
|
|
70 ^ ^ ^^
|
|
71
|
|
72 Note that these word boundaries only apply for word motion and
|
|
73 marking commands such as \\[forward-word]. This mode does not affect word
|
|
74 boundaries in found by regexp matching (`\\>', `\\w' &c).
|
|
75
|
|
76 This style of identifiers is common in environments like Java ones,
|
|
77 where underscores aren't trendy enough. Capitalization rules are
|
|
78 sometimes part of the language, e.g. Haskell, which may encourage such
|
|
79 a style. It is appropriate to add `capitalized-words-mode' to the
|
|
80 mode hook for programming langauge modes in which you encounter such
|
|
81 variables, e.g. `java-mode-hook', since it's unlikely to cause trouble
|
|
82 if such identifiers aren't used.
|
|
83
|
|
84 See also `glasses-mode' and `studlify-word'.
|
|
85 Obsoletes `c-forward-into-nomenclature'."
|
|
86 nil " Caps" nil :group 'programming
|
|
87 (set (make-local-variable 'next-word-boundary-function-table)
|
|
88 capitalized-next-word-boundary-function-table))
|
|
89
|
|
90 (provide 'cap-words)
|
|
91 ;;; cap-words.el ends here
|