emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/objed 430d858 037/216: Add more command to move objects


From: Stefan Monnier
Subject: [elpa] externals/objed 430d858 037/216: Add more command to move objects around and change bindings for them
Date: Tue, 8 Jan 2019 12:29:07 -0500 (EST)

branch: externals/objed
commit 430d85843eb152b6adc8f9410711134e1cb775b1
Author: Clemera <address@hidden>
Commit: Clemera <address@hidden>

    Add more command to move objects around and change bindings for them
---
 README.asc | 43 ++++++++++++++++++++++-------------
 objed.el   | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 91 insertions(+), 28 deletions(-)

diff --git a/README.asc b/README.asc
index 8cae9ce..a3dcee5 100644
--- a/README.asc
+++ b/README.asc
@@ -181,22 +181,6 @@ Basic movement commands (switch the object type on 
movement):
        kbd:[s/r].  You can still access kbd:[M-s/r] regular bindings
        by using Meta-shift (kbd:[M-S/R]).
 
-Shifted movement keys:
-
-[`objed-map`]
-|===
-|Shortcut |Purpose
-
-|kbd:[F/B]
-|Move/indent all lines in object right/leftward.
-
-|kbd:[S/R]
-|Move/indent all lines in object to right/leftward to tab stop.
-
-|kbd:[N/P]
-|Move object down/up (exchange current with next/previous object).
-|===
-
 
 Commands for block objects (objects built out of lines of text):
 
@@ -258,6 +242,33 @@ Commands to switch to other objects (and move point to its 
start):
 |Prefix to switch to other objects, see `objed-object-map` for available 
objects and `objed-define-object` to add your own.
 |===
 
+
+Indent/Move objects around:
+
+[`objed-map`]
+|===
+|Shortcut |Purpose
+
+|kbd:[C-left/C-right]
+|Move/indent all lines in object right/leftward.
+
+|kbd:[M-left/M-right]
+|Move/indent all lines in object to right/leftward to tab stop.
+
+|kbd:[F/B]
+|Switch to char object and move it forward/backward.
+
+|kbd:[S/R]
+|Switch to word object and move it forward/backward.
+
+|kbd:[N/P]
+|Switch to line object and move it forward/backward.
+
+|kbd:[T/H]
+|Move current object forward/backward.
+|===
+
+
 Commands to edit objects (applying operations to them). When the
 region is active the operation acts on the current region. To act on
 multiple objects at once you can mark them first (see the "Misc
diff --git a/objed.el b/objed.el
index 95884b2..dc7efa3 100644
--- a/objed.el
+++ b/objed.el
@@ -644,19 +644,25 @@ object as an argument."
     (define-key map "b" (objed--call-and-switch backward-char char))
     (define-key map "f" (objed--call-and-switch forward-char char))
 
-    (define-key map "B" 'objed-indent-left)
-    (define-key map "F" 'objed-indent-right)
-
+    (define-key map "B" 'objed-move-char-backward)
+    (define-key map "F" 'objed-move-char-forward)
+    
     (define-key map "s" (objed--call-and-switch forward-word word))
     (define-key map "r" (objed--call-and-switch backward-word word))
 
-    (define-key map "S" 'objed-indent-to-right-tab-stop)
-    (define-key map "R" 'objed-indent-to-left-tab-stop)
-
+    (define-key map "S" 'objed-move-word-forward)
+    (define-key map "R" 'objed-move-word-backward)
+    
     (define-key map "p" (objed--call-and-switch previous-line line))
     (define-key map "n" (objed--call-and-switch next-line line))
-    (define-key map "N" 'objed-move-object-forward)
-    (define-key map "P" 'objed-move-object-backward)
+
+    (define-key map "P" 'objed-move-line-backward)
+    (define-key map "N" 'objed-move-line-forward)
+    
+    (define-key map (kbd "<C-left>") 'objed-indent-left)
+    (define-key map (kbd "<C-right>") 'objed-indent-right)
+    (define-key map (kbd "<M-right>") 'objed-indent-to-right-tab-stop)
+    (define-key map (kbd "<M-left>") 'objed-indent-to-left-tab-stop)
     
     (define-key map "`" 'objed-backward-symbol)
     (define-key map "ยด" 'objed-forward-symbol)
@@ -669,6 +675,10 @@ object as an argument."
     ;; context expansions
     (define-key map "t" 'objed-current-or-previous-context)
     (define-key map "h" 'objed-current-or-next-context)
+    (define-key map "T" 'objed-move-object-backward)
+    (define-key map "H" 'objed-move-object-forward)
+
+
     (define-key map "o" 'objed-expand-context)
     (define-key map "u" 'objed-upto-context)
 
@@ -2057,13 +2067,13 @@ ARG is passed to `yank'. On repreat `yank-pop'."
 
 (defvar objed--indent-map
   (let ((map (make-sparse-keymap)))
-    (define-key map (kbd "F") 'objed-indent-right)
-    (define-key map (kbd "B") 'objed-indent-left)
+    (define-key map (kbd "<C-right>") 'objed-indent-right)
+    (define-key map (kbd "<C-left>") 'objed-indent-left)
     (define-key map (kbd "<left>") 'objed-indent-left)
     (define-key map (kbd "<right>") 'objed-indent-right)
     (define-key map (kbd "TAB") 'objed-indent)
-    (define-key map (kbd "R") 'objed-indent-to-left-tab-stop)
-    (define-key map (kbd "S") 'objed-indent-to-right-tab-stop)
+    (define-key map (kbd "<M-left>") 'objed-indent-to-left-tab-stop)
+    (define-key map (kbd "<M-right>") 'objed-indent-to-right-tab-stop)
     map)
   "Map used for indentation.")
 
@@ -2186,6 +2196,48 @@ Swaps the current object with the previous one."
      (objed-make-object :beg pbeg :end (point)))
     (goto-char (objed--beg))))
 
+
+(defun objed--switch-and-move (o dir)
+  "Switch to object O and move it in direction DIR."
+  (interactive)
+  (unless (eq objed--object o)
+    (objed--switch-to o))
+  (cond ((eq dir 'forward)
+        (objed-move-object-forward))
+       ((eq dir 'backward)
+        (objed-move-object-backward))))
+        
+(defun objed-move-char-forward ()
+  "Switch to char object and move it forward."
+  (interactive)
+  (objed--switch-and-move 'char 'forward))
+
+(defun objed-move-char-backward ()
+  "Switch to char object and move it backward."
+  (interactive)
+  (objed--switch-and-move 'char 'backward))
+
+(defun objed-move-word-forward ()
+  "Switch to word object and move it forward."
+  (interactive)
+  (objed--switch-and-move 'word 'forward))
+
+(defun objed-move-word-backward ()
+  "Switch to word object and move it backward."
+  (interactive)
+  (objed--switch-and-move 'word 'backward))
+
+(defun objed-move-line-backward ()
+  "Switch to line object and move it backward."
+  (interactive)
+  (objed--switch-and-move 'line 'backward))
+
+(defun objed-move-line-forward ()
+  "Switch to line object and move it forward."
+  (interactive)
+  (objed--switch-and-move 'line 'forward))
+
+
 (defun objed-narrow (&optional arg)
   "Narrow to object.
 



reply via email to

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