changeset 106160:b27aeda9c1fd

2009-11-20 Tassilo Horn <tassilo@member.fsf.org> * progmodes/cc-cmds.el (c-update-modeline) (c-forward-into-nomenclature, c-backward-into-nomenclature): Refer to subword.el functions instead of cc-subword.el. * progmodes/cc-mode.el (subword-mode, c-mode-base-map): Refer to subword.el functions instead of cc-subword.el. * progmodes/cc-subword.el: Renamed to subword.el. * subword.el: Renamed from progmodes/cc-subword.el. (subword-mode-map): Renamed from c-subword-mode-map. (subword-mode): Renamed from c-subword-mode. (global-subword-mode): New global minor mode. (forward-subword): Renamed from c-forward-subword. (backward-subword): Renamed from c-backward-subword. (mark-subword): Renamed from c-mark-subword. (kill-subword): Renamed from c-kill-subword. (backward-kill-subword): Renamed from c-backward-kill-subword. (transpose-subwords): Renamed from c-tranpose-subword. (downcase-subword): Renamed from c-downcase-subword. (capitalize-subword): Renamed from c-capitalize-subword. (forward-subword-internal): Renamed from c-forward-subword-internal. (backward-subword-internal): Renamed from c-backward-subword-internal.
author Tassilo Horn <tassilo@member.fsf.org>
date Fri, 20 Nov 2009 08:22:32 +0000
parents f5e8e91b23bf
children 0ea716305b13
files lisp/ChangeLog lisp/progmodes/cc-cmds.el lisp/progmodes/cc-langs.el lisp/progmodes/cc-mode.el lisp/progmodes/cc-subword.el lisp/subword.el
diffstat 6 files changed, 323 insertions(+), 311 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Fri Nov 20 06:56:16 2009 +0000
+++ b/lisp/ChangeLog	Fri Nov 20 08:22:32 2009 +0000
@@ -1,3 +1,30 @@
+2009-11-20  Tassilo Horn  <tassilo@member.fsf.org>
+
+	* progmodes/cc-cmds.el (c-update-modeline)
+	(c-forward-into-nomenclature, c-backward-into-nomenclature): Refer
+	to subword.el functions instead of cc-subword.el.
+
+	* progmodes/cc-mode.el (subword-mode, c-mode-base-map): Refer to
+	subword.el functions instead of cc-subword.el.
+
+	* progmodes/cc-subword.el: Renamed to subword.el.
+	* subword.el: Renamed from progmodes/cc-subword.el.
+	(subword-mode-map): Renamed from c-subword-mode-map.
+	(subword-mode): Renamed from c-subword-mode.
+	(global-subword-mode): New global minor mode.
+	(forward-subword): Renamed from c-forward-subword.
+	(backward-subword): Renamed from c-backward-subword.
+	(mark-subword): Renamed from c-mark-subword.
+	(kill-subword): Renamed from c-kill-subword.
+	(backward-kill-subword): Renamed from c-backward-kill-subword.
+	(transpose-subwords): Renamed from c-tranpose-subword.
+	(downcase-subword): Renamed from c-downcase-subword.
+	(capitalize-subword): Renamed from c-capitalize-subword.
+	(forward-subword-internal): Renamed from
+	c-forward-subword-internal.
+	(backward-subword-internal): Renamed from
+	c-backward-subword-internal.
+
 2009-11-20  Dan Nicolaescu  <dann@ics.uci.edu>
 
 	* vc.el (vc-deduce-fileset): Allow non-state changing operations
--- a/lisp/progmodes/cc-cmds.el	Fri Nov 20 06:56:16 2009 +0000
+++ b/lisp/progmodes/cc-cmds.el	Fri Nov 20 08:22:32 2009 +0000
@@ -50,8 +50,6 @@
 (cc-bytecomp-defun delete-forward-p)	; XEmacs
 (cc-bytecomp-defvar filladapt-mode)	; c-fill-paragraph contains a kludge
 					; which looks at this.
-(cc-bytecomp-defun c-forward-subword)
-(cc-bytecomp-defun c-backward-subword)
 
 ;; Indentation / Display syntax functions
 (defvar c-fix-backslashes t)
@@ -263,9 +261,9 @@
 			 "a" "")
 		     (if c-hungry-delete-key "h" "")
 		     (if (and
-			  ;; cc-subword might not be loaded.
-			  (boundp 'c-subword-mode)
-			  (symbol-value 'c-subword-mode))
+			  ;; subword might not be loaded.
+			  (boundp 'subword-mode)
+			  (symbol-value 'subword-mode))
 			 "w"
 		       "")))
 	(bare-mode-name (if (string-match "\\(^[^/]*\\)/" mode-name)
@@ -1328,16 +1326,16 @@
 (defun c-forward-into-nomenclature (&optional arg)
   "Compatibility alias for `c-forward-subword'."
   (interactive "p")
-  (require 'cc-subword)
-  (c-forward-subword arg))
-(make-obsolete 'c-forward-into-nomenclature 'c-forward-subword "22.1")
+  (require 'subword)
+  (forward-subword arg))
+(make-obsolete 'c-forward-into-nomenclature 'forward-subword "23.2")
 
 (defun c-backward-into-nomenclature (&optional arg)
   "Compatibility alias for `c-backward-subword'."
   (interactive "p")
-  (require 'cc-subword)
-  (c-backward-subword arg))
-(make-obsolete 'c-backward-into-nomenclature 'c-backward-subword "22.1")
+  (require 'subword)
+  (backward-subword arg))
+(make-obsolete 'c-backward-into-nomenclature 'backward-subword "23.2")
 
 (defun c-scope-operator ()
   "Insert a double colon scope operator at point.
--- a/lisp/progmodes/cc-langs.el	Fri Nov 20 06:56:16 2009 +0000
+++ b/lisp/progmodes/cc-langs.el	Fri Nov 20 08:22:32 2009 +0000
@@ -306,9 +306,9 @@
 	:style toggle :selected c-auto-newline]
        ["Hungry delete"         c-toggle-hungry-state
 	:style toggle :selected c-hungry-delete-key]
-       ["Subword mode"          c-subword-mode
-	:style toggle :selected (and (boundp 'c-subword-mode)
-                                     c-subword-mode)])))
+       ["Subword mode"          subword-mode
+	:style toggle :selected (and (boundp 'subword-mode)
+                                     subword-mode)])))
 
 
 ;;; Syntax tables.
--- a/lisp/progmodes/cc-mode.el	Fri Nov 20 06:56:16 2009 +0000
+++ b/lisp/progmodes/cc-mode.el	Fri Nov 20 08:22:32 2009 +0000
@@ -113,7 +113,7 @@
 
 ;; Autoload directive for emacsen that doesn't have an older CC Mode
 ;; version in the dist.
-(autoload 'c-subword-mode "cc-subword"
+(autoload 'subword-mode "subword"
   "Mode enabling subword movement and editing keys." t)
 
 ;; Load cc-fonts first after font-lock is loaded, since it isn't
@@ -379,7 +379,7 @@
   ;; conflicts with OOBR
   ;;(define-key c-mode-base-map "\C-c\C-v"  'c-version)
   ;; (define-key c-mode-base-map "\C-c\C-y"  'c-toggle-hungry-state)  Commented out by ACM, 2005-11-22.
-  (define-key c-mode-base-map "\C-c\C-w" 'c-subword-mode)
+  (define-key c-mode-base-map "\C-c\C-w" 'subword-mode)
   )
 
 ;; We don't require the outline package, but we configure it a bit anyway.
--- a/lisp/progmodes/cc-subword.el	Fri Nov 20 06:56:16 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,295 +0,0 @@
-;;; cc-subword.el --- Handling capitalized subwords in a nomenclature
-
-;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
-
-;; Author: Masatake YAMATO
-
-;; This file is part of GNU Emacs.
-
-;; GNU Emacs is free software: you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; GNU Emacs is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; This package provides `subword' oriented commands and a minor mode
-;; (`c-subword-mode') that substitutes the common word handling
-;; functions with them.
-
-;; 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:
-
-;;  Nomenclature           Subwords
-;;  ===========================================================
-;;  GtkWindow          =>  "Gtk" and "Window"
-;;  EmacsFrameClass    =>  "Emacs", "Frame" and "Class"
-;;  NSGraphicsContext  =>  "NS", "Graphics" and "Context"
-
-;; The subword oriented commands defined in this package recognize
-;; subwords in a nomenclature to move between them and to edit them as
-;; words.
-
-;; In the minor mode, all common key bindings for word oriented
-;; commands are overridden by the subword oriented commands:
-
-;; Key     Word oriented command      Subword oriented command
-;; ============================================================
-;; M-f     `forward-word'             `c-forward-subword'
-;; M-b     `backward-word'            `c-backward-subword'
-;; M-@     `mark-word'                `c-mark-subword'
-;; M-d     `kill-word'                `c-kill-subword'
-;; M-DEL   `backward-kill-word'       `c-backward-kill-subword'
-;; M-t     `transpose-words'          `c-transpose-subwords'
-;; M-c     `capitalize-word'          `c-capitalize-subword'
-;; M-u     `upcase-word'              `c-upcase-subword'
-;; M-l     `downcase-word'            `c-downcase-subword'
-;;
-;; Note: If you have changed the key bindings for the word oriented
-;; commands in your .emacs or a similar place, the keys you've changed
-;; to are also used for the corresponding subword oriented commands.
-
-;; To make the mode turn on automatically, put the following code in
-;; your .emacs:
-;;
-;; (add-hook 'c-mode-common-hook
-;; 	  (lambda () (c-subword-mode 1)))
-;;
-
-;; Acknowledgment:
-;; The regular expressions to detect subwords are mostly based on
-;; the old `c-forward-into-nomenclature' originally contributed by
-;; Terry_Glanfield dot Southern at rxuk dot xerox dot com.
-
-;; TODO: ispell-word and subword oriented C-w in isearch.
-
-;;; Code:
-
-(eval-when-compile
-  (let ((load-path
-	 (if (and (boundp 'byte-compile-dest-file)
-		  (stringp byte-compile-dest-file))
-	     (cons (file-name-directory byte-compile-dest-file) load-path)
-	   load-path)))
-    (load "cc-bytecomp" nil t)))
-
-(cc-require 'cc-defs)
-(cc-require 'cc-cmds)
-
-(defvar c-subword-mode-map
-  (let ((map (make-sparse-keymap)))
-    (dolist (cmd '(forward-word backward-word mark-word
-                                kill-word backward-kill-word
-                                transpose-words
-                                capitalize-word upcase-word downcase-word))
-      (let ((othercmd (let ((name (symbol-name cmd)))
-                        (string-match "\\(.*-\\)\\(word.*\\)" name)
-                        (intern (concat "c-"
-                                        (match-string 1 name)
-                                        "sub"
-                                        (match-string 2 name))))))
-        (if (fboundp 'command-remapping)
-            (define-key map (vector 'remap cmd) othercmd)
-          (substitute-key-definition cmd othercmd map global-map))))
-    map)
-  "Keymap used in command `c-subword-mode' minor mode.")
-
-;;;###autoload
-(define-minor-mode c-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:
-
-  Nomenclature           Subwords
-  ===========================================================
-  GtkWindow          =>  \"Gtk\" and \"Window\"
-  EmacsFrameClass    =>  \"Emacs\", \"Frame\" and \"Class\"
-  NSGraphicsContext  =>  \"NS\", \"Graphics\" and \"Context\"
-
-The subword oriented commands activated in this minor mode recognize
-subwords in a nomenclature to move between subwords and to edit them
-as words.
-
-\\{c-subword-mode-map}"
-    nil
-    nil
-    c-subword-mode-map
-    (c-update-modeline))
-
-(defun c-forward-subword (&optional arg)
-  "Do the same as `forward-word' but on subwords.
-See the command `c-subword-mode' for a description of subwords.
-Optional argument ARG is the same as for `forward-word'."
-  (interactive "p")
-  (unless arg (setq arg 1))
-  (c-keep-region-active)
-  (cond
-   ((< 0 arg)
-    (dotimes (i arg (point))
-      (c-forward-subword-internal)))
-   ((> 0 arg)
-    (dotimes (i (- arg) (point))
-      (c-backward-subword-internal)))
-   (t
-    (point))))
-
-(put 'c-forward-subword 'CUA 'move)
-
-(defun c-backward-subword (&optional arg)
-  "Do the same as `backward-word' but on subwords.
-See the command `c-subword-mode' for a description of subwords.
-Optional argument ARG is the same as for `backward-word'."
-  (interactive "p")
-  (c-forward-subword (- (or arg 1))))
-
-(defun c-mark-subword (arg)
-  "Do the same as `mark-word' but on subwords.
-See the command `c-subword-mode' for a description of subwords.
-Optional argument ARG is the same as for `mark-word'."
-  ;; This code is almost copied from `mark-word' in GNU Emacs.
-  (interactive "p")
-  (cond ((and (eq last-command this-command) (mark t))
-	 (set-mark
-	  (save-excursion
-	    (goto-char (mark))
-	    (c-forward-subword arg)
-	    (point))))
-	(t
-	 (push-mark
-	  (save-excursion
-	    (c-forward-subword arg)
-	    (point))
-	  nil t))))
-
-(put 'c-backward-subword 'CUA 'move)
-
-(defun c-kill-subword (arg)
-  "Do the same as `kill-word' but on subwords.
-See the command `c-subword-mode' for a description of subwords.
-Optional argument ARG is the same as for `kill-word'."
-  (interactive "p")
-  (kill-region (point) (c-forward-subword arg)))
-
-(defun c-backward-kill-subword (arg)
-  "Do the same as `backward-kill-word' but on subwords.
-See the command `c-subword-mode' for a description of subwords.
-Optional argument ARG is the same as for `backward-kill-word'."
-  (interactive "p")
-  (c-kill-subword (- arg)))
-
-(defun c-transpose-subwords (arg)
-  "Do the same as `transpose-words' but on subwords.
-See the command `c-subword-mode' for a description of subwords.
-Optional argument ARG is the same as for `transpose-words'."
-  (interactive "*p")
-  (transpose-subr 'c-forward-subword arg))
-
-
-
-(defun c-downcase-subword (arg)
-  "Do the same as `downcase-word' but on subwords.
-See the command `c-subword-mode' for a description of subwords.
-Optional argument ARG is the same as for `downcase-word'."
-  (interactive "p")
-  (let ((start (point)))
-    (downcase-region (point) (c-forward-subword arg))
-    (when (< arg 0) 
-      (goto-char start))))
-
-(defun c-upcase-subword (arg)
-  "Do the same as `upcase-word' but on subwords.
-See the command `c-subword-mode' for a description of subwords.
-Optional argument ARG is the same as for `upcase-word'."
-  (interactive "p")
-  (let ((start (point)))
-    (upcase-region (point) (c-forward-subword arg))
-    (when (< arg 0) 
-      (goto-char start))))
-
-(defun c-capitalize-subword (arg)
-  "Do the same as `capitalize-word' but on subwords.
-See the command `c-subword-mode' for a description of subwords.
-Optional argument ARG is the same as for `capitalize-word'."
-  (interactive "p")
-  (let ((count (abs arg))
-	(start (point))
-	(advance (if (< arg 0) nil t)))
-    (dotimes (i count)
-      (if advance
-	  (progn (re-search-forward
-		  (concat "[" c-alpha "]")
-		  nil t)
-		 (goto-char (match-beginning 0)))
-	(c-backward-subword))
-      (let* ((p (point))
-	     (pp (1+ p))
-	     (np (c-forward-subword)))
-	(upcase-region p pp)
-	(downcase-region pp np)
-	(goto-char (if advance np p))))
-    (unless advance
-      (goto-char start))))
-
-
-
-;;
-;; Internal functions
-;;
-(defun c-forward-subword-internal ()
-  (if (and
-       (save-excursion
-	 (let ((case-fold-search nil))
-	   (re-search-forward
-	    (concat "\\W*\\(\\([" c-upper "]*\\W?\\)[" c-lower c-digit "]*\\)")
-	    nil t)))
-       (> (match-end 0) (point))) ; So we don't get stuck at a
-				  ; "word-constituent" which isn't c-upper,
-				  ; c-lower or c-digit
-      (goto-char
-       (cond
-	((< 1 (- (match-end 2) (match-beginning 2)))
-	 (1- (match-end 2)))
-	(t
-	 (match-end 0))))
-    (forward-word 1)))
-
-
-(defun c-backward-subword-internal ()
-  (if (save-excursion
-	(let ((case-fold-search nil))
-	  (re-search-backward
-	   (concat
-	    "\\(\\(\\W\\|[" c-lower c-digit "]\\)\\([" c-upper "]+\\W*\\)"
-	    "\\|\\W\\w+\\)")
-	   nil t)))
-      (goto-char
-       (cond
-	((and (match-end 3)
-	      (< 1 (- (match-end 3) (match-beginning 3)))
-	      (not (eq (point) (match-end 3))))
-	 (1- (match-end 3)))
-	(t
-	 (1+ (match-beginning 0)))))
-    (backward-word 1)))
-
-
-(cc-provide 'cc-subword)
-
-;; arch-tag: 2be9d294-7f30-4626-95e6-9964bb93c7a3
-;;; cc-subword.el ends here
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lisp/subword.el	Fri Nov 20 08:22:32 2009 +0000
@@ -0,0 +1,282 @@
+;;; subword.el --- Handling capitalized subwords in a nomenclature
+
+;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+
+;; Author: Masatake YAMATO
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This package was cc-submode.el before it was recognized being
+;; useful in general and not tied to C and c-mode at all.
+
+;; This package provides `subword' oriented commands and a minor mode
+;; (`subword-mode') that substitutes the common word handling
+;; functions with them.
+
+;; 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:
+
+;;  Nomenclature           Subwords
+;;  ===========================================================
+;;  GtkWindow          =>  "Gtk" and "Window"
+;;  EmacsFrameClass    =>  "Emacs", "Frame" and "Class"
+;;  NSGraphicsContext  =>  "NS", "Graphics" and "Context"
+
+;; The subword oriented commands defined in this package recognize
+;; subwords in a nomenclature to move between them and to edit them as
+;; words.
+
+;; In the minor mode, all common key bindings for word oriented
+;; commands are overridden by the subword oriented commands:
+
+;; Key     Word oriented command      Subword oriented command
+;; ============================================================
+;; M-f     `forward-word'             `forward-subword'
+;; M-b     `backward-word'            `backward-subword'
+;; M-@     `mark-word'                `mark-subword'
+;; M-d     `kill-word'                `kill-subword'
+;; M-DEL   `backward-kill-word'       `backward-kill-subword'
+;; M-t     `transpose-words'          `transpose-subwords'
+;; M-c     `capitalize-word'          `capitalize-subword'
+;; M-u     `upcase-word'              `upcase-subword'
+;; M-l     `downcase-word'            `downcase-subword'
+;;
+;; Note: If you have changed the key bindings for the word oriented
+;; commands in your .emacs or a similar place, the keys you've changed
+;; to are also used for the corresponding subword oriented commands.
+
+;; To make the mode turn on automatically, put the following code in
+;; your .emacs:
+;;
+;; (add-hook 'c-mode-common-hook
+;; 	  (lambda () (subword-mode 1)))
+;;
+
+;; Acknowledgment:
+;; The regular expressions to detect subwords are mostly based on
+;; the old `c-forward-into-nomenclature' originally contributed by
+;; Terry_Glanfield dot Southern at rxuk dot xerox dot com.
+
+;; TODO: ispell-word and subword oriented C-w in isearch.
+
+;;; Code:
+
+(defvar subword-mode-map
+  (let ((map (make-sparse-keymap)))
+    (dolist (cmd '(forward-word backward-word mark-word kill-word
+				backward-kill-word transpose-words
+                                capitalize-word upcase-word downcase-word))
+      (let ((othercmd (let ((name (symbol-name cmd)))
+                        (string-match "\\(.*-\\)\\(word.*\\)" name)
+                        (intern (concat (match-string 1 name)
+                                        "sub"
+                                        (match-string 2 name))))))
+        (define-key map (vector 'remap cmd) othercmd)))
+    map)
+  "Keymap used in `subword-mode' minor mode.")
+
+;;;###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:
+
+  Nomenclature           Subwords
+  ===========================================================
+  GtkWindow          =>  \"Gtk\" and \"Window\"
+  EmacsFrameClass    =>  \"Emacs\", \"Frame\" and \"Class\"
+  NSGraphicsContext  =>  \"NS\", \"Graphics\" and \"Context\"
+
+The subword oriented commands activated in this minor mode recognize
+subwords in a nomenclature to move between subwords and to edit them
+as words.
+
+\\{subword-mode-map}"
+    nil
+    nil
+    subword-mode-map)
+
+(define-obsolete-function-alias 'c-subword-mode 'subword-mode "23.2")
+
+;;;###autoload
+(define-global-minor-mode global-subword-mode subword-mode
+  (lambda () (subword-mode 1)))
+
+(defun forward-subword (&optional arg)
+  "Do the same as `forward-word' but on subwords.
+See the command `subword-mode' for a description of subwords.
+Optional argument ARG is the same as for `forward-word'."
+  (interactive "p")
+  (unless arg (setq arg 1))
+  (cond
+   ((< 0 arg)
+    (dotimes (i arg (point))
+      (forward-subword-internal)))
+   ((> 0 arg)
+    (dotimes (i (- arg) (point))
+      (backward-subword-internal)))
+   (t
+    (point))))
+
+(put 'forward-subword 'CUA 'move)
+
+(defun backward-subword (&optional arg)
+  "Do the same as `backward-word' but on subwords.
+See the command `subword-mode' for a description of subwords.
+Optional argument ARG is the same as for `backward-word'."
+  (interactive "p")
+  (forward-subword (- (or arg 1))))
+
+(defun mark-subword (arg)
+  "Do the same as `mark-word' but on subwords.
+See the command `subword-mode' for a description of subwords.
+Optional argument ARG is the same as for `mark-word'."
+  ;; This code is almost copied from `mark-word' in GNU Emacs.
+  (interactive "p")
+  (cond ((and (eq last-command this-command) (mark t))
+	 (set-mark
+	  (save-excursion
+	    (goto-char (mark))
+	    (forward-subword arg)
+	    (point))))
+	(t
+	 (push-mark
+	  (save-excursion
+	    (forward-subword arg)
+	    (point))
+	  nil t))))
+
+(put 'backward-subword 'CUA 'move)
+
+(defun kill-subword (arg)
+  "Do the same as `kill-word' but on subwords.
+See the command `subword-mode' for a description of subwords.
+Optional argument ARG is the same as for `kill-word'."
+  (interactive "p")
+  (kill-region (point) (forward-subword arg)))
+
+(defun backward-kill-subword (arg)
+  "Do the same as `backward-kill-word' but on subwords.
+See the command `subword-mode' for a description of subwords.
+Optional argument ARG is the same as for `backward-kill-word'."
+  (interactive "p")
+  (kill-subword (- arg)))
+
+(defun transpose-subwords (arg)
+  "Do the same as `transpose-words' but on subwords.
+See the command `subword-mode' for a description of subwords.
+Optional argument ARG is the same as for `transpose-words'."
+  (interactive "*p")
+  (transpose-subr 'forward-subword arg))
+
+(defun downcase-subword (arg)
+  "Do the same as `downcase-word' but on subwords.
+See the command `subword-mode' for a description of subwords.
+Optional argument ARG is the same as for `downcase-word'."
+  (interactive "p")
+  (let ((start (point)))
+    (downcase-region (point) (forward-subword arg))
+    (when (< arg 0)
+      (goto-char start))))
+
+(defun upcase-subword (arg)
+  "Do the same as `upcase-word' but on subwords.
+See the command `subword-mode' for a description of subwords.
+Optional argument ARG is the same as for `upcase-word'."
+  (interactive "p")
+  (let ((start (point)))
+    (upcase-region (point) (forward-subword arg))
+    (when (< arg 0)
+      (goto-char start))))
+
+(defun capitalize-subword (arg)
+  "Do the same as `capitalize-word' but on subwords.
+See the command `subword-mode' for a description of subwords.
+Optional argument ARG is the same as for `capitalize-word'."
+  (interactive "p")
+  (let ((count (abs arg))
+	(start (point))
+	(advance (if (< arg 0) nil t)))
+    (dotimes (i count)
+      (if advance
+	  (progn (re-search-forward
+		  (concat "[[:alpha:]]")
+		  nil t)
+		 (goto-char (match-beginning 0)))
+	(backward-subword))
+      (let* ((p (point))
+	     (pp (1+ p))
+	     (np (forward-subword)))
+	(upcase-region p pp)
+	(downcase-region pp np)
+	(goto-char (if advance np p))))
+    (unless advance
+      (goto-char start))))
+
+
+
+;;
+;; Internal functions
+;;
+(defun forward-subword-internal ()
+  (if (and
+       (save-excursion
+	 (let ((case-fold-search nil))
+	   (re-search-forward
+	    (concat "\\W*\\(\\([[:upper:]]*\\W?\\)[[:lower:][:digit:]]*\\)")
+	    nil t)))
+       (> (match-end 0) (point)))
+      (goto-char
+       (cond
+	((< 1 (- (match-end 2) (match-beginning 2)))
+	 (1- (match-end 2)))
+	(t
+	 (match-end 0))))
+    (forward-word 1)))
+
+
+(defun backward-subword-internal ()
+  (if (save-excursion
+	(let ((case-fold-search nil))
+	  (re-search-backward
+	   (concat
+	    "\\(\\(\\W\\|[[:lower:][:digit:]]\\)\\([[:upper:]]+\\W*\\)"
+	    "\\|\\W\\w+\\)")
+	   nil t)))
+      (goto-char
+       (cond
+	((and (match-end 3)
+	      (< 1 (- (match-end 3) (match-beginning 3)))
+	      (not (eq (point) (match-end 3))))
+	 (1- (match-end 3)))
+	(t
+	 (1+ (match-beginning 0)))))
+    (backward-word 1)))
+
+
+(provide 'subword)
+
+;;; subword.el ends here