annotate lisp/progmodes/glasses.el @ 76076:59abcab48ea2

(menubar_active): Remove menu_command_in_progress.
author Jason Rumney <jasonr@gnu.org>
date Thu, 22 Feb 2007 22:50:15 +0000
parents e3694f1cb928
children c1ec1c8a8d2e 95d0cdf160ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1 ;;; glasses.el --- make cantReadThis readable
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 74547
diff changeset
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
74547
183eba998a4d Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 74079
diff changeset
4 ;; Free Software Foundation, Inc.
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5
38176
2a85f8119924 (glasses-make-readable): Consider
Gerd Moellmann <gerd@gnu.org>
parents: 34473
diff changeset
6 ;; Author: Milan Zamazal <pdm@zamazal.org>
2a85f8119924 (glasses-make-readable): Consider
Gerd Moellmann <gerd@gnu.org>
parents: 34473
diff changeset
7 ;; Maintainer: Milan Zamazal <pdm@zamazal.org>
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; Keywords: tools
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; any later version.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 61285
diff changeset
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 61285
diff changeset
25 ;; Boston, MA 02110-1301, USA.
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 ;; This file defines a minor mode for making unreadableIdentifiersLikeThis
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ;; readable. In some environments, for instance Java, it is common to use such
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 ;; unreadable identifiers. It is not good to use underscores in identifiers of
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 ;; your own project in such an environment to make your sources more readable,
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 ;; since it introduces undesirable confusion, which is worse than the
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 ;; unreadability. Fortunately, you use Emacs for the subproject, so the
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 ;; problem can be solved some way.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 ;;
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 ;; This file defines the `glasses-mode' minor mode, which displays underscores
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 ;; between all the pairs of lower and upper English letters. (This only
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;; displays underscores, the text is not changed actually.) Alternatively, you
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 ;; can say you want the capitals in some given face (e.g. bold).
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 ;;
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 ;; The mode does something usable, though not perfect. Improvement suggestions
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 ;; from Emacs experts are welcome.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 ;;
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 ;; If you like in-identifier separators different from underscores, change the
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 ;; value of the variable `glasses-separator' appropriately. See also the
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 ;; variables `glasses-face' and `glasses-convert-on-write-p'. You can also use
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 ;; the command `M-x customize-group RET glasses RET'.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 ;;
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 ;; If you set any of the variables `glasses-separator' or `glasses-face' after
28498
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
51 ;; glasses.el is loaded in a different way than through customize, you
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 ;; should call the function `glasses-set-overlay-properties' afterwards.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 ;;; Code:
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 (eval-when-compile
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 (require 'cl))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 ;;; User variables
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 (defgroup glasses nil
28498
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
65 "Make unreadable code likeThis(one) readable."
30814
1b2e8bd62f76 (glasses) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30523
diff changeset
66 :version "21.1"
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 :group 'tools)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 (defcustom glasses-separator "_"
69123
618d3bbab8be Remove unnecessary leading * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68790
diff changeset
71 "String to be displayed as a visual separator in identifiers.
68790
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
72 It is used both for adding missing separators and for replacing separators
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
73 defined by `glasses-original-separator'. If you don't want to add missing
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
74 separators, set `glasses-separator' to an empty string. If you don't want to
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
75 replace existent separators, set `glasses-original-separator' to an empty
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
76 string."
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 :group 'glasses
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 :type 'string
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 :set 'glasses-custom-set
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 :initialize 'custom-initialize-default)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82
68790
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
83 (defcustom glasses-original-separator "_"
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
84 "*String to be displayed as `glasses-separator' in separator positions.
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
85 For instance, if you set it to \"_\" and set `glasses-separator' to \"-\",
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
86 underscore separators are displayed as hyphens.
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
87 If `glasses-original-separator' is an empty string, no such display change is
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
88 performed."
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
89 :group 'glasses
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
90 :type 'string
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
91 :set 'glasses-custom-set
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
92 :initialize 'custom-initialize-default
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
93 :version "22.1")
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
94
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
95
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 (defcustom glasses-face nil
69123
618d3bbab8be Remove unnecessary leading * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68790
diff changeset
97 "Face to be put on capitals of an identifier looked through glasses.
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 If it is nil, no face is placed at the capitalized letter.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 For example, you can set `glasses-separator' to an empty string and
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 `glasses-face' to `bold'. Then unreadable identifiers will have no separators,
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 but will have their capitals in bold."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 :group 'glasses
67912
24b085b97616 (glasses-face): Add tag "None" to const nil.
Juri Linkov <juri@jurta.org>
parents: 67862
diff changeset
104 :type '(choice (const :tag "None" nil) face)
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 :set 'glasses-custom-set
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 :initialize 'custom-initialize-default)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108
28498
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
109 (defcustom glasses-separate-parentheses-p t
69123
618d3bbab8be Remove unnecessary leading * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68790
diff changeset
110 "If non-nil, ensure space between an identifier and an opening parenthesis."
28498
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
111 :group 'glasses
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
112 :type 'boolean)
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
113
74079
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
114 (defcustom glasses-separate-parentheses-exceptions
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
115 '("^#[\t ]*define[\t ]*[A-Za-z0-9_-]* ?($")
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
116 "List of regexp that are exceptions for `glasses-separate-parentheses-p'.
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
117 They are matched to the current line truncated to the point where the
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
118 parenthesis expression starts."
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
119 :group 'glasses
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
120 :type '(repeat regexp))
28498
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
121
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
122 (defcustom glasses-uncapitalize-p nil
69123
618d3bbab8be Remove unnecessary leading * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68790
diff changeset
123 "If non-nil, downcase embedded capital letters in identifiers.
28498
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
124 Only identifiers starting with lower case letters are affected, letters inside
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
125 other identifiers are unchanged."
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
126 :group 'glasses
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
127 :type 'boolean
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
128 :set 'glasses-custom-set
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
129 :initialize 'custom-initialize-default)
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
130
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
131
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
132 (defcustom glasses-uncapitalize-regexp "[a-z]"
69123
618d3bbab8be Remove unnecessary leading * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68790
diff changeset
133 "Regexp matching beginnings of words to be uncapitalized.
28498
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
134 Only words starting with this regexp are uncapitalized.
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
135 The regexp is case sensitive.
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
136 It has any effect only when `glasses-uncapitalize-p' is non-nil."
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
137 :group 'glasses
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
138 :type 'regexp
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
139 :set 'glasses-custom-set
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
140 :initialize 'custom-initialize-default)
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
141
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
142
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 (defcustom glasses-convert-on-write-p nil
69123
618d3bbab8be Remove unnecessary leading * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68790
diff changeset
144 "If non-nil, remove separators when writing glasses buffer to a file.
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 If you are confused by glasses so much, that you write the separators into code
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 during coding, set this variable to t. The separators will be removed on each
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 file write then.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 Note the removal action does not try to be much clever, so it can remove real
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 separators too."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 :group 'glasses
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 :type 'boolean)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 (defun glasses-custom-set (symbol value)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 "Set value of the variable SYMBOL to VALUE and update overlay categories.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 Used in :set parameter of some customized glasses variables."
30814
1b2e8bd62f76 (glasses) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30523
diff changeset
158 (set-default symbol value)
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 (glasses-set-overlay-properties))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 ;;; Utility functions
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163
74079
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
164 (defun glasses-parenthesis-exception-p (beg end)
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
165 "Tell if (BEG, END) is an exception to `glasses-separate-parentheses-p'.
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
166 See `glasses-separate-parentheses-exceptions'."
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
167 (save-match-data
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
168 (let ((str (buffer-substring beg end)))
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
169 (catch 'match
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
170 (dolist (re glasses-separate-parentheses-exceptions)
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
171 (and (string-match re str) (throw 'match t)))))))
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 (defun glasses-set-overlay-properties ()
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 "Set properties of glasses overlays.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 Consider current setting of user variables."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 ;; In-identifier overlay
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 (put 'glasses 'evaporate t)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 (put 'glasses 'before-string glasses-separator)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 (put 'glasses 'face glasses-face)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180 ;; Beg-identifier overlay
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181 (put 'glasses-init 'evaporate t)
28498
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
182 (put 'glasses-init 'face glasses-face)
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
183 ;; Parenthesis overlay
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
184 (put 'glasses-parenthesis 'evaporate t)
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
185 (put 'glasses-parenthesis 'before-string " "))
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 (glasses-set-overlay-properties)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 (defun glasses-overlay-p (overlay)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 "Return whether OVERLAY is an overlay of glasses mode."
28498
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
192 (memq (overlay-get overlay 'category)
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
193 '(glasses glasses-init glasses-parenthesis)))
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195
28498
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
196 (defun glasses-make-overlay (beg end &optional category)
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
197 "Create and return readability overlay over the region from BEG to END.
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
198 CATEGORY is the overlay category. If it is nil, use the `glasses' category."
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 (let ((overlay (make-overlay beg end)))
28498
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
200 (overlay-put overlay 'category (or category 'glasses))
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
201 overlay))
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 (defun glasses-make-readable (beg end)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205 "Make identifiers in the region from BEG to END readable."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 (let ((case-fold-search nil))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 (save-excursion
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 (save-match-data
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 ;; Face only
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 (goto-char beg)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 (while (re-search-forward
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 "\\<\\([A-Z]\\)[a-zA-Z]*\\([a-z][A-Z]\\|[A-Z][a-z]\\)"
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 end t)
28498
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
214 (glasses-make-overlay (match-beginning 1) (match-end 1)
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
215 'glasses-init))
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
216 ;; Face + separator
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 (goto-char beg)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 (while (re-search-forward "[a-z]\\([A-Z]\\)\\|[A-Z]\\([A-Z]\\)[a-z]"
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 end t)
28498
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
220 (let* ((n (if (match-string 1) 1 2))
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
221 (o (glasses-make-overlay (match-beginning n) (match-end n))))
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
222 (goto-char (match-beginning n))
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
223 (when (and glasses-uncapitalize-p
30523
87bca20b7a83 (glasses-make-readable): Fix uncapitalization of
Gerd Moellmann <gerd@gnu.org>
parents: 28810
diff changeset
224 (save-match-data
87bca20b7a83 (glasses-make-readable): Fix uncapitalization of
Gerd Moellmann <gerd@gnu.org>
parents: 28810
diff changeset
225 (looking-at "[A-Z]\\($\\|[^A-Z]\\)"))
28498
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
226 (save-excursion
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
227 (save-match-data
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
228 (re-search-backward "\\<.")
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
229 (looking-at glasses-uncapitalize-regexp))))
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
230 (overlay-put o 'invisible t)
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
231 (overlay-put o 'after-string (downcase (match-string n))))))
65564
d84981e3d7d4 (glasses-make-readable): If glasses-separator differs from underscore,
Eli Zaretskii <eliz@gnu.org>
parents: 64085
diff changeset
232 ;; Separator change
68790
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
233 (when (and (not (string= glasses-original-separator glasses-separator))
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
234 (not (string= glasses-original-separator "")))
65564
d84981e3d7d4 (glasses-make-readable): If glasses-separator differs from underscore,
Eli Zaretskii <eliz@gnu.org>
parents: 64085
diff changeset
235 (goto-char beg)
68790
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
236 (let ((original-regexp (regexp-quote glasses-original-separator)))
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
237 (while (re-search-forward
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
238 (format "[a-zA-Z0-9]\\(\\(%s\\)+\\)[a-zA-Z0-9]"
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
239 original-regexp)
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
240 end t)
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
241 (goto-char (match-beginning 1))
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
242 (while (looking-at original-regexp)
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
243 (let ((o (glasses-make-overlay (point) (1+ (point)))))
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
244 ;; `concat' ensures the character properties won't merge
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
245 (overlay-put o 'display (concat glasses-separator)))
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
246 (goto-char (match-end 0))))))
28498
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
247 ;; Parentheses
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
248 (when glasses-separate-parentheses-p
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
249 (goto-char beg)
38176
2a85f8119924 (glasses-make-readable): Consider
Gerd Moellmann <gerd@gnu.org>
parents: 34473
diff changeset
250 (while (re-search-forward "[a-zA-Z]_*\\(\(\\)" end t)
74079
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
251 (unless (glasses-parenthesis-exception-p (point-at-bol) (match-end 1))
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
252 (glasses-make-overlay (match-beginning 1) (match-end 1)
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
253 'glasses-parenthesis))))))))
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
254
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
255
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
256 (defun glasses-make-unreadable (beg end)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257 "Return identifiers in the region from BEG to END to their unreadable state."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258 (dolist (o (overlays-in beg end))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 (when (glasses-overlay-p o)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 (delete-overlay o))))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263 (defun glasses-convert-to-unreadable ()
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264 "Convert current buffer to unreadable identifiers and return nil.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 This function modifies buffer contents, it removes all the separators,
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266 recognized according to the current value of the variable `glasses-separator'."
74079
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
267 (when glasses-convert-on-write-p
28810
4756047a4398 (glasses-convert-to-unreadable): Use
Gerd Moellmann <gerd@gnu.org>
parents: 28498
diff changeset
268 (let ((case-fold-search nil)
4756047a4398 (glasses-convert-to-unreadable): Use
Gerd Moellmann <gerd@gnu.org>
parents: 28498
diff changeset
269 (separator (regexp-quote glasses-separator)))
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 (save-excursion
74079
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
271 (unless (string= glasses-separator "")
68790
29a4ce0514ee (glasses-separator): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68773
diff changeset
272 (goto-char (point-min))
74079
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
273 (while (re-search-forward
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
274 (format "[a-z]\\(%s\\)[A-Z]\\|[A-Z]\\(%s\\)[A-Z][a-z]"
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
275 separator separator)
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
276 nil t)
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
277 (let ((n (if (match-string 1) 1 2)))
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
278 (replace-match "" t nil nil n)
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
279 (goto-char (match-end n))))
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
280 (unless (string= glasses-separator glasses-original-separator)
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
281 (goto-char (point-min))
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
282 (while (re-search-forward (format "[a-zA-Z0-9]\\(%s+\\)[a-zA-Z0-9]"
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
283 separator)
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
284 nil t)
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
285 (replace-match glasses-original-separator nil nil nil 1)
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
286 (goto-char (match-beginning 1)))))
28498
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
287 (when glasses-separate-parentheses-p
809168962c9b Provide facilities for inserting space before left
Gerd Moellmann <gerd@gnu.org>
parents: 27469
diff changeset
288 (goto-char (point-min))
39088
2fc21ed3beac (glasses-convert-to-unreadable): Consider
Gerd Moellmann <gerd@gnu.org>
parents: 38176
diff changeset
289 (while (re-search-forward "[a-zA-Z]_*\\( \\)\(" nil t)
74079
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
290 (unless (glasses-parenthesis-exception-p (point-at-bol) (1+ (match-end 1)))
71cb863df348 (glasses-separate-parentheses-exceptions): New. Exceptions to the rule "add
Juanma Barranquero <lekktu@gmail.com>
parents: 69123
diff changeset
291 (replace-match "" t nil nil 1)))))))
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292 ;; nil must be returned to allow use in write file hooks
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
293 nil)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
294
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
295
34473
e859388caea4 Use `define-minor-mode' for the minor mode
Gerd Moellmann <gerd@gnu.org>
parents: 34338
diff changeset
296 (defun glasses-change (beg end &optional old-len)
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
297 "After-change function updating glass overlays."
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
298 (let ((beg-line (save-excursion (goto-char beg) (line-beginning-position)))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
299 (end-line (save-excursion (goto-char end) (line-end-position))))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
300 (glasses-make-unreadable beg-line end-line)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
301 (glasses-make-readable beg-line end-line)))
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
302
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
303
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 ;;; Minor mode definition
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307 ;;;###autoload
34473
e859388caea4 Use `define-minor-mode' for the minor mode
Gerd Moellmann <gerd@gnu.org>
parents: 34338
diff changeset
308 (define-minor-mode glasses-mode
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309 "Minor mode for making identifiers likeThis readable.
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 When this mode is active, it tries to add virtual separators (like underscores)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311 at places they belong to."
61285
bb8465da2472 (glasses-mode): Specify :group.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
312 :group 'glasses :lighter " o^o"
34473
e859388caea4 Use `define-minor-mode' for the minor mode
Gerd Moellmann <gerd@gnu.org>
parents: 34338
diff changeset
313 (save-excursion
e859388caea4 Use `define-minor-mode' for the minor mode
Gerd Moellmann <gerd@gnu.org>
parents: 34338
diff changeset
314 (save-restriction
e859388caea4 Use `define-minor-mode' for the minor mode
Gerd Moellmann <gerd@gnu.org>
parents: 34338
diff changeset
315 (widen)
e859388caea4 Use `define-minor-mode' for the minor mode
Gerd Moellmann <gerd@gnu.org>
parents: 34338
diff changeset
316 ;; We erase all the overlays anyway, to avoid dual sight in some
e859388caea4 Use `define-minor-mode' for the minor mode
Gerd Moellmann <gerd@gnu.org>
parents: 34338
diff changeset
317 ;; circumstances
e859388caea4 Use `define-minor-mode' for the minor mode
Gerd Moellmann <gerd@gnu.org>
parents: 34338
diff changeset
318 (glasses-make-unreadable (point-min) (point-max))
e859388caea4 Use `define-minor-mode' for the minor mode
Gerd Moellmann <gerd@gnu.org>
parents: 34338
diff changeset
319 (if glasses-mode
e859388caea4 Use `define-minor-mode' for the minor mode
Gerd Moellmann <gerd@gnu.org>
parents: 34338
diff changeset
320 (progn
e859388caea4 Use `define-minor-mode' for the minor mode
Gerd Moellmann <gerd@gnu.org>
parents: 34338
diff changeset
321 (jit-lock-register 'glasses-change)
e859388caea4 Use `define-minor-mode' for the minor mode
Gerd Moellmann <gerd@gnu.org>
parents: 34338
diff changeset
322 (add-hook 'local-write-file-hooks
e859388caea4 Use `define-minor-mode' for the minor mode
Gerd Moellmann <gerd@gnu.org>
parents: 34338
diff changeset
323 'glasses-convert-to-unreadable nil t))
e859388caea4 Use `define-minor-mode' for the minor mode
Gerd Moellmann <gerd@gnu.org>
parents: 34338
diff changeset
324 (jit-lock-unregister 'glasses-change)
e859388caea4 Use `define-minor-mode' for the minor mode
Gerd Moellmann <gerd@gnu.org>
parents: 34338
diff changeset
325 (remove-hook 'local-write-file-hooks
e859388caea4 Use `define-minor-mode' for the minor mode
Gerd Moellmann <gerd@gnu.org>
parents: 34338
diff changeset
326 'glasses-convert-to-unreadable t)))))
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329 ;;; Announce
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 (provide 'glasses)
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
332
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333
69123
618d3bbab8be Remove unnecessary leading * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68790
diff changeset
334 ;; arch-tag: a3515167-c89e-484f-90a1-d85143e52b12
27469
98f24cb3efa5 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335 ;;; glasses.el ends here