annotate lisp/progmodes/cap-words.el @ 91359:259402c3ba6a

*** empty log message ***
author Kenichi Handa <handa@m17n.org>
date Mon, 28 Jan 2008 07:12:03 +0000
parents 8f03b3660640
children 9341564706fb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
90746
8f03b3660640 *** empty log message ***
Juanma Barranquero <lekktu@gmail.com>
parents: 89911
diff changeset
1 ;;; cap-words.el --- minor mode for motion in CapitalizedWordIdentifiers
89311
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
2
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 2002 Free Software Foundation, Inc.
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
4
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
5 ;; Author: Dave Love <fx@gnu.org>
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
6 ;; Keywords: languages
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
7
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
8 ;; This file is free software; you can redistribute it and/or modify
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
9 ;; it under the terms of the GNU General Public License as published by
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
11 ;; any later version.
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
12
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
13 ;; This file is distributed in the hope that it will be useful,
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
16 ;; GNU General Public License for more details.
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
17
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
20 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
21 ;; Boston, MA 02111-1307, USA.
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
22
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
23 ;;; Commentary:
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
24
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
25 ;; Provides Capitalized Words minor mode for word movement in
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
26 ;; identifiers CapitalizedLikeThis.
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
27
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
28 ;; Note that the same effect could be obtained by frobbing the
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
29 ;; category of upper case characters to produce word boundaries, but
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
30 ;; the necessary processing isn't done for ASCII characters.
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
31
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
32 ;; Fixme: This doesn't work properly for mouse double clicks.
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
33
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
34 ;;; Code:
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
35
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
36 (defun capitalized-next-word-boundary (pos limit)
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
37 "Function for use in `next-word-boundary-function-table'.
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
38 Looks for word boundaries before capitals."
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
39 (save-excursion
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
40 (goto-char pos)
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
41 (let (case-fold-search)
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
42 (if (<= pos limit)
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
43 ;; Fixme: Are these regexps the best?
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
44 (or (and (re-search-forward "\\=.\\w*[[:upper:]]"
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
45 limit t)
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
46 (progn (backward-char)
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
47 t))
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
48 (re-search-forward "\\>" limit t))
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
49 (or (re-search-backward "[[:upper:]]\\w*\\=" limit t)
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
50 (re-search-backward "\\<" limit t))))
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
51 (point)))
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
52
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
53 (defconst capitalized-next-word-boundary-function-table
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
54 (let ((tab (make-char-table nil)))
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
55 (set-char-table-range tab t #'capitalized-next-word-boundary)
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
56 tab)
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
57 "Assigned to `next-word-boundary-function-table' in Capitalized Words mode.")
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
58
89499
47e2e534b750 (capitalized-words-mode): Add autoload
Dave Love <fx@gnu.org>
parents: 89311
diff changeset
59 ;;;###autoload
89311
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
60 (define-minor-mode capitalized-words-mode
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
61 "Toggle Capitalized- Words mode.
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
62
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
63 In this minor mode, a word boundary occurs immediately before an
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
64 uppercase letter in a symbol. This is in addition to all the normal
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
65 boundaries given by the syntax and category tables. There is no
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
66 restriction to ASCII.
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
67
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
68 E.g. the beginning of words in the following identifier are as marked:
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
69
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
70 capitalizedWorDD
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
71 ^ ^ ^^
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
72
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
73 Note that these word boundaries only apply for word motion and
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
74 marking commands such as \\[forward-word]. This mode does not affect word
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
75 boundaries in found by regexp matching (`\\>', `\\w' &c).
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
76
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
77 This style of identifiers is common in environments like Java ones,
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
78 where underscores aren't trendy enough. Capitalization rules are
89499
47e2e534b750 (capitalized-words-mode): Add autoload
Dave Love <fx@gnu.org>
parents: 89311
diff changeset
79 sometimes part of the language, e.g. Haskell, which may thus encourage
47e2e534b750 (capitalized-words-mode): Add autoload
Dave Love <fx@gnu.org>
parents: 89311
diff changeset
80 such a style. It is appropriate to add `capitalized-words-mode' to
47e2e534b750 (capitalized-words-mode): Add autoload
Dave Love <fx@gnu.org>
parents: 89311
diff changeset
81 the mode hook for programming langauge modes in which you encounter
47e2e534b750 (capitalized-words-mode): Add autoload
Dave Love <fx@gnu.org>
parents: 89311
diff changeset
82 variables like this, e.g. `java-mode-hook'. It's unlikely to cause
47e2e534b750 (capitalized-words-mode): Add autoload
Dave Love <fx@gnu.org>
parents: 89311
diff changeset
83 trouble if such identifiers aren't used.
89311
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
84
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
85 See also `glasses-mode' and `studlify-word'.
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
86 Obsoletes `c-forward-into-nomenclature'."
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
87 nil " Caps" nil :group 'programming
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
88 (set (make-local-variable 'next-word-boundary-function-table)
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
89 capitalized-next-word-boundary-function-table))
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
90
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
91 (provide 'cap-words)
89911
cce857c68ba2 Add arch taglines
Miles Bader <miles@gnu.org>
parents: 89499
diff changeset
92
cce857c68ba2 Add arch taglines
Miles Bader <miles@gnu.org>
parents: 89499
diff changeset
93 ;;; arch-tag: 46513b64-fe5a-4c0b-902c-ed235c22975f
89311
f81bc2f13a1b *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
94 ;;; cap-words.el ends here