Merge from emacs-24; up to 2012-12-19T13:01:16Z!michael.albinus@gmx.de
[bpt/emacs.git] / lisp / progmodes / subword.el
index 7df42c8..80e632c 100644 (file)
@@ -1,6 +1,6 @@
 ;;; subword.el --- Handling capitalized subwords in a nomenclature
 
-;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
 
 ;; Author: Masatake YAMATO
 
 
 ;;; 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
 
 ;;;###autoload
 (define-minor-mode subword-mode
-  "Mode enabling subword movement and editing keys.
-In spite of GNU Coding Standards, it is popular to name a symbol by
-mixing uppercase and lowercase letters, e.g. \"GtkWidget\",
-\"EmacsFrameClass\", \"NSGraphicsContext\", etc.  Here we call these
-mixed case symbols `nomenclatures'. Also, each capitalized (or
-completely uppercase) part of a nomenclature is called a `subword'.
-Here are some examples:
+  "Toggle subword movement and editing (Subword mode).
+With a prefix argument ARG, enable Subword mode if ARG is
+positive, and disable it otherwise.  If called from Lisp, enable
+the mode if ARG is omitted or nil.
+
+Subword mode is a buffer-local minor mode.  Enabling it remaps
+word-based editing commands to subword-based commands that handle
+symbols with mixed uppercase and lowercase letters,
+e.g. \"GtkWidget\", \"EmacsFrameClass\", \"NSGraphicsContext\".
+
+Here we call these mixed case symbols `nomenclatures'.  Each
+capitalized (or completely uppercase) part of a nomenclature is
+called a `subword'.  Here are some examples:
 
   Nomenclature           Subwords
   ===========================================================
@@ -132,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))))
 
@@ -243,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
@@ -259,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)
@@ -277,5 +291,4 @@ Optional argument ARG is the same as for `capitalize-word'."
 \f
 (provide 'subword)
 
-;; arch-tag: b8a01202-8a52-4a71-ae0a-d753fafd67ef
 ;;; subword.el ends here