Commit 002668e1 authored by Ted Zlatanov's avatar Ted Zlatanov
Browse files

Add `superword-mode'

parent 40693bba
...@@ -254,6 +254,11 @@ has not been relevant for some time. ...@@ -254,6 +254,11 @@ has not been relevant for some time.
* New Modes and Packages in Emacs 24.4 * New Modes and Packages in Emacs 24.4
** New `superword-mode' in subword.el
`superword-mode' overrides the default word motion commands to treat
symbol_words as a single word, similar to what `subword-mode' does and
using the same internal functions.
** New nadvice.el package offering lighter-weight advice facilities. ** New nadvice.el package offering lighter-weight advice facilities.
It is layered as: It is layered as:
- add-function/remove-function which can be used to add/remove code on any - add-function/remove-function which can be used to add/remove code on any
......
2013-03-27 Teodor Zlatanov <tzz@lifelogs.com>
* progmodes/subword.el: Add `superword-mode' to do word motion
over symbol_words (parallels and leverages `subword-mode' which
does word motion inside MixedCaseWords).
2013-03-26 Stefan Monnier <monnier@iro.umontreal.ca> 2013-03-26 Stefan Monnier <monnier@iro.umontreal.ca>
   
* desktop.el (desktop--v2s): Rename from desktop-internal-v2s. * desktop.el (desktop--v2s): Rename from desktop-internal-v2s.
......
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
;; This package provides `subword' oriented commands and a minor mode ;; This package provides `subword' oriented commands and a minor mode
;; (`subword-mode') that substitutes the common word handling ;; (`subword-mode') that substitutes the common word handling
;; functions with them. ;; functions with them. It also provides the `superword-mode' minor
;; mode that treats symbols as words, the opposite of `subword-mode'.
;; In spite of GNU Coding Standards, it is popular to name a symbol by ;; In spite of GNU Coding Standards, it is popular to name a symbol by
;; mixing uppercase and lowercase letters, e.g. "GtkWidget", ;; mixing uppercase and lowercase letters, e.g. "GtkWidget",
...@@ -43,12 +44,13 @@ ...@@ -43,12 +44,13 @@
;; The subword oriented commands defined in this package recognize ;; The subword oriented commands defined in this package recognize
;; subwords in a nomenclature to move between them and to edit them as ;; subwords in a nomenclature to move between them and to edit them as
;; words. ;; words. You also get a mode to treat symbols as words instead,
;; called `superword-mode' (the opposite of `subword-mode').
;; In the minor mode, all common key bindings for word oriented ;; In the minor mode, all common key bindings for word oriented
;; commands are overridden by the subword oriented commands: ;; commands are overridden by the subword oriented commands:
;; Key Word oriented command Subword oriented command ;; Key Word oriented command Subword oriented command (also superword)
;; ============================================================ ;; ============================================================
;; M-f `forward-word' `subword-forward' ;; M-f `forward-word' `subword-forward'
;; M-b `backward-word' `subword-backward' ;; M-b `backward-word' `subword-backward'
...@@ -67,8 +69,13 @@ ...@@ -67,8 +69,13 @@
;; To make the mode turn on automatically, put the following code in ;; To make the mode turn on automatically, put the following code in
;; your .emacs: ;; your .emacs:
;; ;;
;; (add-hook 'c-mode-common-hook ;; (add-hook 'c-mode-common-hook 'subword-mode)
;; (lambda () (subword-mode 1))) ;;
;; To make the mode turn `superword-mode' on automatically for
;; only some modes, put the following code in your .emacs:
;;
;; (add-hook 'c-mode-common-hook 'superword-mode)
;; ;;
;; Acknowledgment: ;; Acknowledgment:
...@@ -98,7 +105,8 @@ ...@@ -98,7 +105,8 @@
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
(dolist (cmd '(forward-word backward-word mark-word kill-word (dolist (cmd '(forward-word backward-word mark-word kill-word
backward-kill-word transpose-words backward-kill-word transpose-words
capitalize-word upcase-word downcase-word)) capitalize-word upcase-word downcase-word
left-word right-word))
(let ((othercmd (let ((name (symbol-name cmd))) (let ((othercmd (let ((name (symbol-name cmd)))
(string-match "\\([[:alpha:]-]+\\)-word[s]?" name) (string-match "\\([[:alpha:]-]+\\)-word[s]?" name)
(intern (concat "subword-" (match-string 1 name)))))) (intern (concat "subword-" (match-string 1 name))))))
...@@ -133,9 +141,8 @@ subwords in a nomenclature to move between subwords and to edit them ...@@ -133,9 +141,8 @@ subwords in a nomenclature to move between subwords and to edit them
as words. as words.
\\{subword-mode-map}" \\{subword-mode-map}"
nil :lighter " ,"
nil (when subword-mode (superword-mode -1)))
subword-mode-map)
(define-obsolete-function-alias 'c-subword-mode 'subword-mode "23.2") (define-obsolete-function-alias 'c-subword-mode 'subword-mode "23.2")
...@@ -161,6 +168,8 @@ Optional argument ARG is the same as for `forward-word'." ...@@ -161,6 +168,8 @@ Optional argument ARG is the same as for `forward-word'."
(put 'subword-forward 'CUA 'move) (put 'subword-forward 'CUA 'move)
(defalias 'subword-right 'subword-forward)
(defun subword-backward (&optional arg) (defun subword-backward (&optional arg)
"Do the same as `backward-word' but on subwords. "Do the same as `backward-word' but on subwords.
See the command `subword-mode' for a description of subwords. See the command `subword-mode' for a description of subwords.
...@@ -168,6 +177,8 @@ Optional argument ARG is the same as for `backward-word'." ...@@ -168,6 +177,8 @@ Optional argument ARG is the same as for `backward-word'."
(interactive "p") (interactive "p")
(subword-forward (- (or arg 1)))) (subword-forward (- (or arg 1))))
(defalias 'subword-left 'subword-backward)
(defun subword-mark (arg) (defun subword-mark (arg)
"Do the same as `mark-word' but on subwords. "Do the same as `mark-word' but on subwords.
See the command `subword-mode' for a description of subwords. See the command `subword-mode' for a description of subwords.
...@@ -254,41 +265,73 @@ Optional argument ARG is the same as for `capitalize-word'." ...@@ -254,41 +265,73 @@ Optional argument ARG is the same as for `capitalize-word'."
(unless advance (unless advance
(goto-char start)))) (goto-char start))))
(defvar superword-mode-map subword-mode-map
"Keymap used in `superword-mode' minor mode.")
;;;###autoload
(define-minor-mode superword-mode
"Toggle superword movement and editing (Superword mode).
With a prefix argument ARG, enable Superword mode if ARG is
positive, and disable it otherwise. If called from Lisp, enable
the mode if ARG is omitted or nil.
Superword mode is a buffer-local minor mode. Enabling it remaps
word-based editing commands to superword-based commands that
treat symbols as words, e.g. \"this_is_a_symbol\".
The superword oriented commands activated in this minor mode
recognize symbols as superwords to move between superwords and to
edit them as words.
\\{superword-mode-map}"
:lighter " ²"
(when superword-mode (subword-mode -1)))
;;;###autoload
(define-global-minor-mode global-superword-mode superword-mode
(lambda () (superword-mode 1)))
;; ;;
;; Internal functions ;; Internal functions
;; ;;
(defun subword-forward-internal () (defun subword-forward-internal ()
(if (and (if superword-mode
(save-excursion (forward-symbol 1)
(let ((case-fold-search nil)) (if (and
(re-search-forward subword-forward-regexp nil t))) (save-excursion
(> (match-end 0) (point))) (let ((case-fold-search nil))
(goto-char (re-search-forward subword-forward-regexp nil t)))
(cond (> (match-end 0) (point)))
((< 1 (- (match-end 2) (match-beginning 2))) (goto-char
(1- (match-end 2))) (cond
(t ((< 1 (- (match-end 2) (match-beginning 2)))
(match-end 0)))) (1- (match-end 2)))
(forward-word 1))) (t
(match-end 0))))
(forward-word 1))))
(defun subword-backward-internal () (defun subword-backward-internal ()
(if (save-excursion (if superword-mode
(let ((case-fold-search nil)) (forward-symbol -1)
(re-search-backward subword-backward-regexp nil t))) (if (save-excursion
(goto-char (let ((case-fold-search nil))
(cond (re-search-backward subword-backward-regexp nil t)))
((and (match-end 3) (goto-char
(< 1 (- (match-end 3) (match-beginning 3))) (cond
(not (eq (point) (match-end 3)))) ((and (match-end 3)
(1- (match-end 3))) (< 1 (- (match-end 3) (match-beginning 3)))
(t (not (eq (point) (match-end 3))))
(1+ (match-beginning 0))))) (1- (match-end 3)))
(backward-word 1))) (t
(1+ (match-beginning 0)))))
(backward-word 1))))
(provide 'subword) (provide 'subword)
(provide 'superword)
;;; subword.el ends here ;;; subword.el ends here
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment