emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Use of command remapping in cc-subword.el


From: Stefan Monnier
Subject: Use of command remapping in cc-subword.el
Date: Mon, 03 Apr 2006 18:09:19 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Any objection to the patch below?


        Stefan


--- cc-subword.el       17 Feb 2006 10:49:16 -0500      1.2
+++ cc-subword.el       03 Apr 2006 18:05:46 -0400      
@@ -91,6 +91,24 @@
 ;; Don't complain about the `define-minor-mode' form if it isn't defined.
 (cc-bytecomp-defvar c-subword-mode)
 
+(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 (if (consp cmd) (prog1 (cdr cmd) (setq cmd (car cmd)))
+                        (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)))))
+  "Keymap used in command `c-subword-mode' minor mode.")
+
 ;;; Autoload directives must be on the top level, so we construct an
 ;;; autoload form instead.
 ;;;###autoload (autoload 'c-subword-mode "cc-subword" "Mode enabling subword 
movement and editing keys." t)
@@ -105,41 +123,6 @@
       (error
        "c-subword-mode is not (yet) available in this version of (X)Emacs.  
Sorry!"))
 
-  (defvar c-subword-mode-map
-    (let ((map (make-sparse-keymap)))
-      (substitute-key-definition 'forward-word
-                                'c-forward-subword
-                                map global-map)
-      (substitute-key-definition 'backward-word
-                                'c-backward-subword
-                                map global-map)
-      (substitute-key-definition 'mark-word
-                                'c-mark-subword
-                                map global-map)
-    
-      (substitute-key-definition 'kill-word
-                                'c-kill-subword
-                                map global-map)
-      (substitute-key-definition 'backward-kill-word
-                                'c-backward-kill-subword
-                                map global-map)
-    
-      (substitute-key-definition 'transpose-words
-                                'c-transpose-subwords
-                                map global-map)
-    
-      (substitute-key-definition 'capitalize-word
-                                'c-capitalize-subword
-                                map global-map)
-      (substitute-key-definition 'upcase-word
-                                'c-upcase-subword
-                                map global-map)
-      (substitute-key-definition 'downcase-word
-                                'c-downcase-subword
-                                map global-map)
-      map)
-    "Keymap used in command `c-subword-mode' minor mode.")
-
   (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
@@ -308,5 +291,5 @@
 
 (cc-provide 'cc-subword)
 
-;;; arch-tag: 2be9d294-7f30-4626-95e6-9964bb93c7a3
+;; arch-tag: 2be9d294-7f30-4626-95e6-9964bb93c7a3
 ;;; cc-subword.el ends here




reply via email to

[Prev in Thread] Current Thread [Next in Thread]