From 1c308380b6f29e389dc10d418b9203a74d64dce2 Mon Sep 17 00:00:00 2001 From: Phil Sainty Date: Wed, 15 Aug 2012 23:25:27 -0700 Subject: [PATCH] Make subword.el easier to customize (tiny change) * lisp/progmodes/subword.el (subword-forward-function) (subword-backward-function, subword-forward-regexp, subword-backward-regexp): New variables. (subword-forward, subword-forward-internal, subword-backward-internal): Use new variables, eg so that different "word" definitions can be easily used. Fixes: debbugs:11411 --- lisp/ChangeLog | 9 +++++++++ lisp/progmodes/subword.el | 28 ++++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index cc42b1493ee..2202b4c7632 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2012-08-16 Phil Sainty (tiny change) + + * progmodes/subword.el (subword-forward-function) + (subword-backward-function, subword-forward-regexp) + (subword-backward-regexp): New variables. + (subword-forward, subword-forward-internal, subword-backward-internal): + Use new variables, eg so that different "word" definitions + can be easily used. (Bug#11411) + 2012-08-15 Stefan Monnier * vc/vc-mtn.el (vc-mtn-revision-completion-table): Handle completion diff --git a/lisp/progmodes/subword.el b/lisp/progmodes/subword.el index 7d8dd4301a2..e541aed8867 100644 --- a/lisp/progmodes/subword.el +++ b/lisp/progmodes/subword.el @@ -80,6 +80,20 @@ ;;; Code: +(defvar subword-forward-function 'subword-forward-internal + "Function to call for forward subword movement.") + +(defvar subword-backward-function 'subword-backward-internal + "Function to call for backward subword movement.") + +(defvar subword-forward-regexp + "\\W*\\(\\([[:upper:]]*\\W?\\)[[:lower:][:digit:]]*\\)" + "Regexp used by `subword-forward-internal'.") + +(defvar subword-backward-regexp + "\\(\\(\\W\\|[[:lower:][:digit:]]\\)\\([[:upper:]]+\\W*\\)\\|\\W\\w+\\)" + "Regexp used by `subword-backward-internal'.") + (defvar subword-mode-map (let ((map (make-sparse-keymap))) (dolist (cmd '(forward-word backward-word mark-word kill-word @@ -138,10 +152,10 @@ Optional argument ARG is the same as for `forward-word'." (cond ((< 0 arg) (dotimes (i arg (point)) - (subword-forward-internal))) + (funcall subword-forward-function))) ((> 0 arg) (dotimes (i (- arg) (point)) - (subword-backward-internal))) + (funcall subword-backward-function))) (t (point)))) @@ -249,9 +263,7 @@ Optional argument ARG is the same as for `capitalize-word'." (if (and (save-excursion (let ((case-fold-search nil)) - (re-search-forward - (concat "\\W*\\(\\([[:upper:]]*\\W?\\)[[:lower:][:digit:]]*\\)") - nil t))) + (re-search-forward subword-forward-regexp nil t))) (> (match-end 0) (point))) (goto-char (cond @@ -265,11 +277,7 @@ Optional argument ARG is the same as for `capitalize-word'." (defun subword-backward-internal () (if (save-excursion (let ((case-fold-search nil)) - (re-search-backward - (concat - "\\(\\(\\W\\|[[:lower:][:digit:]]\\)\\([[:upper:]]+\\W*\\)" - "\\|\\W\\w+\\)") - nil t))) + (re-search-backward subword-backward-regexp nil t))) (goto-char (cond ((and (match-end 3) -- 2.39.2