aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Zlatanov2013-03-27 10:04:34 -0400
committerTed Zlatanov2013-03-27 10:04:34 -0400
commit002668e109fe71527f564a797d4c5e0756e45530 (patch)
tree56aef43f1882dc683d4b76370b4c664f1e0b7051
parent40693bbaa3889dd517f6017bedfceb4a0c12d7a7 (diff)
downloademacs-002668e109fe71527f564a797d4c5e0756e45530.tar.gz
emacs-002668e109fe71527f564a797d4c5e0756e45530.zip
Add `superword-mode'
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/progmodes/subword.el111
3 files changed, 88 insertions, 34 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 1947797bd34..191ddf245f9 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -254,6 +254,11 @@ has not been relevant for some time.
254 254
255 255
256* New Modes and Packages in Emacs 24.4 256* New Modes and Packages in Emacs 24.4
257** New `superword-mode' in subword.el
258`superword-mode' overrides the default word motion commands to treat
259symbol_words as a single word, similar to what `subword-mode' does and
260using the same internal functions.
261
257** New nadvice.el package offering lighter-weight advice facilities. 262** New nadvice.el package offering lighter-weight advice facilities.
258It is layered as: 263It is layered as:
259- add-function/remove-function which can be used to add/remove code on any 264- add-function/remove-function which can be used to add/remove code on any
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e86bc7f0a96..043289ab4a1 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12013-03-27 Teodor Zlatanov <tzz@lifelogs.com>
2
3 * progmodes/subword.el: Add `superword-mode' to do word motion
4 over symbol_words (parallels and leverages `subword-mode' which
5 does word motion inside MixedCaseWords).
6
12013-03-26 Stefan Monnier <monnier@iro.umontreal.ca> 72013-03-26 Stefan Monnier <monnier@iro.umontreal.ca>
2 8
3 * desktop.el (desktop--v2s): Rename from desktop-internal-v2s. 9 * desktop.el (desktop--v2s): Rename from desktop-internal-v2s.
diff --git a/lisp/progmodes/subword.el b/lisp/progmodes/subword.el
index 80e632c6ef6..24abfa8a053 100644
--- a/lisp/progmodes/subword.el
+++ b/lisp/progmodes/subword.el
@@ -26,7 +26,8 @@
26 26
27;; This package provides `subword' oriented commands and a minor mode 27;; This package provides `subword' oriented commands and a minor mode
28;; (`subword-mode') that substitutes the common word handling 28;; (`subword-mode') that substitutes the common word handling
29;; functions with them. 29;; functions with them. It also provides the `superword-mode' minor
30;; mode that treats symbols as words, the opposite of `subword-mode'.
30 31
31;; In spite of GNU Coding Standards, it is popular to name a symbol by 32;; In spite of GNU Coding Standards, it is popular to name a symbol by
32;; mixing uppercase and lowercase letters, e.g. "GtkWidget", 33;; mixing uppercase and lowercase letters, e.g. "GtkWidget",
@@ -43,12 +44,13 @@
43 44
44;; The subword oriented commands defined in this package recognize 45;; The subword oriented commands defined in this package recognize
45;; subwords in a nomenclature to move between them and to edit them as 46;; subwords in a nomenclature to move between them and to edit them as
46;; words. 47;; words. You also get a mode to treat symbols as words instead,
48;; called `superword-mode' (the opposite of `subword-mode').
47 49
48;; In the minor mode, all common key bindings for word oriented 50;; In the minor mode, all common key bindings for word oriented
49;; commands are overridden by the subword oriented commands: 51;; commands are overridden by the subword oriented commands:
50 52
51;; Key Word oriented command Subword oriented command 53;; Key Word oriented command Subword oriented command (also superword)
52;; ============================================================ 54;; ============================================================
53;; M-f `forward-word' `subword-forward' 55;; M-f `forward-word' `subword-forward'
54;; M-b `backward-word' `subword-backward' 56;; M-b `backward-word' `subword-backward'
@@ -67,8 +69,13 @@
67;; To make the mode turn on automatically, put the following code in 69;; To make the mode turn on automatically, put the following code in
68;; your .emacs: 70;; your .emacs:
69;; 71;;
70;; (add-hook 'c-mode-common-hook 72;; (add-hook 'c-mode-common-hook 'subword-mode)
71;; (lambda () (subword-mode 1))) 73;;
74
75;; To make the mode turn `superword-mode' on automatically for
76;; only some modes, put the following code in your .emacs:
77;;
78;; (add-hook 'c-mode-common-hook 'superword-mode)
72;; 79;;
73 80
74;; Acknowledgment: 81;; Acknowledgment:
@@ -98,7 +105,8 @@
98 (let ((map (make-sparse-keymap))) 105 (let ((map (make-sparse-keymap)))
99 (dolist (cmd '(forward-word backward-word mark-word kill-word 106 (dolist (cmd '(forward-word backward-word mark-word kill-word
100 backward-kill-word transpose-words 107 backward-kill-word transpose-words
101 capitalize-word upcase-word downcase-word)) 108 capitalize-word upcase-word downcase-word
109 left-word right-word))
102 (let ((othercmd (let ((name (symbol-name cmd))) 110 (let ((othercmd (let ((name (symbol-name cmd)))
103 (string-match "\\([[:alpha:]-]+\\)-word[s]?" name) 111 (string-match "\\([[:alpha:]-]+\\)-word[s]?" name)
104 (intern (concat "subword-" (match-string 1 name)))))) 112 (intern (concat "subword-" (match-string 1 name))))))
@@ -133,9 +141,8 @@ subwords in a nomenclature to move between subwords and to edit them
133as words. 141as words.
134 142
135\\{subword-mode-map}" 143\\{subword-mode-map}"
136 nil 144 :lighter " ,"
137 nil 145 (when subword-mode (superword-mode -1)))
138 subword-mode-map)
139 146
140(define-obsolete-function-alias 'c-subword-mode 'subword-mode "23.2") 147(define-obsolete-function-alias 'c-subword-mode 'subword-mode "23.2")
141 148
@@ -161,6 +168,8 @@ Optional argument ARG is the same as for `forward-word'."
161 168
162(put 'subword-forward 'CUA 'move) 169(put 'subword-forward 'CUA 'move)
163 170
171(defalias 'subword-right 'subword-forward)
172
164(defun subword-backward (&optional arg) 173(defun subword-backward (&optional arg)
165 "Do the same as `backward-word' but on subwords. 174 "Do the same as `backward-word' but on subwords.
166See the command `subword-mode' for a description of subwords. 175See the command `subword-mode' for a description of subwords.
@@ -168,6 +177,8 @@ Optional argument ARG is the same as for `backward-word'."
168 (interactive "p") 177 (interactive "p")
169 (subword-forward (- (or arg 1)))) 178 (subword-forward (- (or arg 1))))
170 179
180(defalias 'subword-left 'subword-backward)
181
171(defun subword-mark (arg) 182(defun subword-mark (arg)
172 "Do the same as `mark-word' but on subwords. 183 "Do the same as `mark-word' but on subwords.
173See the command `subword-mode' for a description of subwords. 184See the command `subword-mode' for a description of subwords.
@@ -254,41 +265,73 @@ Optional argument ARG is the same as for `capitalize-word'."
254 (unless advance 265 (unless advance
255 (goto-char start)))) 266 (goto-char start))))
256 267
268
269
270(defvar superword-mode-map subword-mode-map
271 "Keymap used in `superword-mode' minor mode.")
272
273;;;###autoload
274(define-minor-mode superword-mode
275 "Toggle superword movement and editing (Superword mode).
276With a prefix argument ARG, enable Superword mode if ARG is
277positive, and disable it otherwise. If called from Lisp, enable
278the mode if ARG is omitted or nil.
279
280Superword mode is a buffer-local minor mode. Enabling it remaps
281word-based editing commands to superword-based commands that
282treat symbols as words, e.g. \"this_is_a_symbol\".
283
284The superword oriented commands activated in this minor mode
285recognize symbols as superwords to move between superwords and to
286edit them as words.
287
288\\{superword-mode-map}"
289 :lighter " ²"
290 (when superword-mode (subword-mode -1)))
291
292;;;###autoload
293(define-global-minor-mode global-superword-mode superword-mode
294 (lambda () (superword-mode 1)))
257 295
258 296
259;; 297;;
260;; Internal functions 298;; Internal functions
261;; 299;;
262(defun subword-forward-internal () 300(defun subword-forward-internal ()
263 (if (and 301 (if superword-mode
264 (save-excursion 302 (forward-symbol 1)
265 (let ((case-fold-search nil)) 303 (if (and
266 (re-search-forward subword-forward-regexp nil t))) 304 (save-excursion
267 (> (match-end 0) (point))) 305 (let ((case-fold-search nil))
268 (goto-char 306 (re-search-forward subword-forward-regexp nil t)))
269 (cond 307 (> (match-end 0) (point)))
270 ((< 1 (- (match-end 2) (match-beginning 2))) 308 (goto-char
271 (1- (match-end 2))) 309 (cond
272 (t 310 ((< 1 (- (match-end 2) (match-beginning 2)))
273 (match-end 0)))) 311 (1- (match-end 2)))
274 (forward-word 1))) 312 (t
275 313 (match-end 0))))
314 (forward-word 1))))
276 315
277(defun subword-backward-internal () 316(defun subword-backward-internal ()
278 (if (save-excursion 317 (if superword-mode
279 (let ((case-fold-search nil)) 318 (forward-symbol -1)
280 (re-search-backward subword-backward-regexp nil t))) 319 (if (save-excursion
281 (goto-char 320 (let ((case-fold-search nil))
282 (cond 321 (re-search-backward subword-backward-regexp nil t)))
283 ((and (match-end 3) 322 (goto-char
284 (< 1 (- (match-end 3) (match-beginning 3))) 323 (cond
285 (not (eq (point) (match-end 3)))) 324 ((and (match-end 3)
286 (1- (match-end 3))) 325 (< 1 (- (match-end 3) (match-beginning 3)))
287 (t 326 (not (eq (point) (match-end 3))))
288 (1+ (match-beginning 0))))) 327 (1- (match-end 3)))
289 (backward-word 1))) 328 (t
329 (1+ (match-beginning 0)))))
330 (backward-word 1))))
290 331
291 332
333
292(provide 'subword) 334(provide 'subword)
335(provide 'superword)
293 336
294;;; subword.el ends here 337;;; subword.el ends here