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

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

[elpa] externals/objed 4527af4 08/16: Replace character based movement w


From: Clemens Radermacher
Subject: [elpa] externals/objed 4527af4 08/16: Replace character based movement with sexp movement commands
Date: Mon, 4 Feb 2019 07:46:28 -0500 (EST)

branch: externals/objed
commit 4527af49c0c59f3bc8518cef680c3770aaf535c3
Author: Clemens Radermacher <address@hidden>
Commit: Clemens Radermacher <address@hidden>

    Replace character based movement with sexp movement commands
    
    For fine grained movement by characters objed exits now because moving by 
char
    units indicates editing mode is more appropriate. This also makes it
    convinient to move with M-f/C-M-f and proceed with f/b.
---
 README.asc                                       | 45 ++++++++--------------
 objed-objects.el                                 |  3 +-
 objed.el                                         | 49 +++++++++++++++---------
 test/tests.el                                    |  3 +-
 test/tests/emacs-lisp-mode/basic-movement/2b     |  4 +-
 test/tests/emacs-lisp-mode/basic-movement/3f     |  4 +-
 test/tests/emacs-lisp-mode/basic-movement/bb     |  4 +-
 test/tests/emacs-lisp-mode/basic-movement/fff    |  4 +-
 test/tests/emacs-lisp-mode/basic-movement/npsrfb |  2 +-
 9 files changed, 59 insertions(+), 59 deletions(-)

diff --git a/README.asc b/README.asc
index d88e403..e069eb1 100644
--- a/README.asc
+++ b/README.asc
@@ -28,16 +28,15 @@ usually insert a character are mapped to objed commands. 
Other keys
 and commands will continue to work as they normally would and exit
 this editing state again.
 
-By default important self inserting keys like kbd:[Space] or
-kbd:[Return] are not bound to modal commands and will exit `objed` on
-insertion. This makes it convenient to move around and continue adding
-new text.
+By default important editing keys like kbd:[Space], kbd:[DEL] or kbd:[Return]
+are not bound to modal commands and will exit `objed` on insertion. Character
+movement exits `objed`, as well. This makes it convenient to move around and
+continue adding/deleting text.
 
-With activation `objed` shows the current object type in the
-`mode-line`. The textual content of the object is highlighted visually
-in the buffer and the cursor color is changed, too. The user can now
-navigate by units of this object, change the object state or switch to
-other object types.
+With activation `objed` shows the current object type in the `mode-line`. The
+textual content of the object is highlighted visually in the buffer and the
+cursor color is changed, too. The user can now navigate by units of this 
object,
+change the object state or switch to other object types.
 
 The object state is either `inner` or `whole` and is indicated in the
 modeline by `(i)` or `(w)` after the object type. With inner state,
@@ -58,12 +57,11 @@ activate `objed` without movement you can use 
`objed-activate`, bound to
 kbd:[M-SPC] by default. It uses the last command and its mapping in
 `objed-command-alist` to choose the initial object.
 
-Objeds modal state provides basic movement commands which move by
-line, word or character. Those switch automatically to the
-corresponding object type, otherwise they work the same as the regular
-Emacs movement commands. Other commands only activate the part between
-the initial position and the new position moved to. By repeating
-commands you can often expand/proceed to other objects. This way you
+Objeds modal state provides basic movement commands which move by line, sexp or
+word. Those switch automatically to the corresponding object type, otherwise
+they work the same as the regular Emacs movement commands. Other commands only
+activate the part between the initial position and the new position moved to. 
By
+repeating commands you can often expand/proceed to other objects. This way you
 can compose movement and editing operations very efficiently.
 
 The expansion commands distinguish between block objects (objects
@@ -185,28 +183,15 @@ Basic movement commands (switch the object type on 
movement):
 |Shortcut |Purpose
 
 |kbd:[f/b]
-|Move forward/backward one character and activate the char object.
+|Move forward/backward one sexp and activate the sexp object
 
 |kbd:[s/r]
-|Move forward/backward one word and activate the word object (***).
+|Move forward/backward one word and activate the word object.
 
 |kbd:[n/p]
 |Move to the next/previous line and activate the line object.
 |===
 
-
-(***): Emacs uses the kbd:[f/b] keys for word AND character movement
-       (depending on the used modifier). I made the decision to remap
-       kbd:[M-f], kbd:[M-b] to kbd:[M-s], kbd:[M-r] in my personal
-       configuration (using `key-translation-map`). This is by no
-       means necessary but might be something to think
-       about. Afterwards you are able to start word movement with
-       kbd:[M-s/r] and continue moving by words with kbd:[s/r] which
-       is more convenient than switching between kbd:[M-b/f] and
-       kbd:[s/r].  You can still access kbd:[M-s/r] regular bindings
-       by using Meta-shift (kbd:[M-S/R]).
-
-
 Commands for block objects (objects built out of lines of text):
 
 [`objed-map`]
diff --git a/objed-objects.el b/objed-objects.el
index 08f595d..5a0c5bf 100644
--- a/objed-objects.el
+++ b/objed-objects.el
@@ -1523,7 +1523,8 @@ Ignores simple structured expressions like words or 
symbols."
                            (eq (point) (progn (setq zigp (zigzag -1))
                                               (point))))))
             (and zigp
-                 (cons (point) zigp))))))))
+                 (cons (min (point) zigp)
+                       (max (point) zigp)))))))))
 
 (objed-define-object nil sexp
   :atp
diff --git a/objed.el b/objed.el
index f365c55..20e45d6 100644
--- a/objed.el
+++ b/objed.el
@@ -182,10 +182,6 @@ function should return nil if objed should not initialize."
 
 (defcustom objed-cmd-alist
   '(
-    (left-char . char)
-    (right-char . char)
-    (backward-char . char)
-    (forward-char . char)
     (forward-word . word)
     (capitalize-word . word)
     (backward-word . word)
@@ -236,8 +232,6 @@ function should return nil if objed should not initialize."
     (objed-next-identifier . identifier)
     (objed-prev-identifier . identifier)
     ;; editing entry commands
-    (delete-char . char)
-    (kill-line . char)
     (yank . region)
     (yank-pop . region)
     ;; misc
@@ -629,11 +623,6 @@ BEFORE and AFTER are forms to execute before/after calling 
the command."
     ;; objed-keeper-commands...
 
     ;; general movement
-    (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-move-char-backward)
-    (define-key map "F" 'objed-move-char-forward)
 
     (define-key map "s" (objed--call-and-switch
                          objed--forward-word
@@ -644,6 +633,13 @@ BEFORE and AFTER are forms to execute before/after calling 
the command."
     (define-key map "S" 'objed-move-word-forward)
     (define-key map "R" 'objed-move-word-backward)
 
+    (define-key map "f" (objed--call-and-switch objed--forward-sexp sexp))
+    (define-key map "b" (objed--call-and-switch objed--backward-sexp sexp))
+
+    ;; TODO: move sexp
+    (define-key map "F" 'objed-move-object-forward)
+    (define-key map "B" 'objed-move-object-backward)
+
     (define-key map "p" (objed--call-and-switch previous-line line))
     (define-key map "n" (objed--call-and-switch
                          next-line line
@@ -656,6 +652,14 @@ BEFORE and AFTER are forms to execute before/after calling 
the command."
     (define-key map "P" 'objed-move-line-backward)
     (define-key map "N" 'objed-move-line-forward)
 
+
+    (define-key map "[" 'objed-current-or-previous-context)
+    (define-key map "]" 'objed-current-or-next-context)
+
+    (define-key map "{" (objed--call-and-switch backward-paragraph paragraph))
+    (define-key map "}" (objed--call-and-switch forward-paragraph paragraph))
+
+
     (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)
@@ -676,10 +680,8 @@ BEFORE and AFTER are forms to execute before/after calling 
the command."
     (define-key map "a" 'objed-beg-of-block)
     (define-key map "e" 'objed-end-of-block)
 
-    ;; context expansions
-    (define-key map "[" 'objed-current-or-previous-context)
-    (define-key map "]" 'objed-current-or-next-context)
 
+    ;; context expansions
     (define-key map "o" 'objed-expand-context)
     (define-key map "u" 'objed-upto-context)
 
@@ -905,8 +907,22 @@ Use `objed-define-dispatch' to define a dispatch command.")
        :end (objed--max o))))))
 
 
+(defun objed--forward-sexp ()
+  (interactive)
+  (while (and (not (eobp))
+              (not (ignore-errors (call-interactively 'forward-sexp) t)))
+    (forward-char 1)))
+
+
+(defun objed--backward-sexp ()
+  (interactive)
+  (while (and (not (bobp))
+              (not (ignore-errors (call-interactively 'backward-sexp) t)))
+    (forward-char -1)))
+
+
 (defmacro objed--save-state (&rest body)
- " Preserve state during execution of BODY."
+ "Preserve state during execution of BODY."
   `(let ((state (objed--get-current-state)))
      (unwind-protect (progn ,@body )
        (prog1 nil (objed--restore-state state)))))
@@ -3087,10 +3103,7 @@ whitespace they build a sequence."
 
 (defvar objed-mode-map
   (let ((map (make-sparse-keymap)))
-    ;; because objed is a "big" addition to the interface overriding M-SPC 
might
-    ;; be ok
     (define-key map (kbd "M-SPC") 'objed-activate)
-    ;;(define-key map (kbd "C-.") 'objed-activate)
     map)
   "Keymap for /function`objed-mode'.")
 
diff --git a/test/tests.el b/test/tests.el
index 10fcf92..37cb41c 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -212,5 +212,6 @@ Insert KEY if there's no command."
 (objed-create-tests emacs-lisp-mode)
 ;; TODO: op tests, marking, remaining commands, other modes
 
-
 (provide 'tests)
+
+
diff --git a/test/tests/emacs-lisp-mode/basic-movement/2b 
b/test/tests/emacs-lisp-mode/basic-movement/2b
index cd55128..4ef9f02 100644
--- a/test/tests/emacs-lisp-mode/basic-movement/2b
+++ b/test/tests/emacs-lisp-mode/basic-movement/2b
@@ -1,8 +1,8 @@
 2b
 ;;;;
 
-Tes|ting line
+Testing li|ne
 
 ;;;;
 
-T|<e>sting line
+|<Testing> line
diff --git a/test/tests/emacs-lisp-mode/basic-movement/3f 
b/test/tests/emacs-lisp-mode/basic-movement/3f
index 3b51b4a..7d066cf 100644
--- a/test/tests/emacs-lisp-mode/basic-movement/3f
+++ b/test/tests/emacs-lisp-mode/basic-movement/3f
@@ -1,8 +1,8 @@
 3f
 ;;;;
 
-Tes|ting line
+Tes|ting line here and there
 
 ;;;;
 
-Testin|<g> line
+Testing line <here>| and there
diff --git a/test/tests/emacs-lisp-mode/basic-movement/bb 
b/test/tests/emacs-lisp-mode/basic-movement/bb
index 3c1e818..11d568c 100644
--- a/test/tests/emacs-lisp-mode/basic-movement/bb
+++ b/test/tests/emacs-lisp-mode/basic-movement/bb
@@ -1,8 +1,8 @@
 bb
 ;;;;
 
-Tes|ting line
+Testing line he|re
 
 ;;;;
 
-T|<e>sting line
+Testing |<line> here
diff --git a/test/tests/emacs-lisp-mode/basic-movement/fff 
b/test/tests/emacs-lisp-mode/basic-movement/fff
index 4f015f9..d9dfb0a 100644
--- a/test/tests/emacs-lisp-mode/basic-movement/fff
+++ b/test/tests/emacs-lisp-mode/basic-movement/fff
@@ -1,8 +1,8 @@
 fff
 ;;;;
 
-Tes|ting line
+Tes|ting line here
 
 ;;;;
 
-Testin|<g> line
+Testing line <here>|
diff --git a/test/tests/emacs-lisp-mode/basic-movement/npsrfb 
b/test/tests/emacs-lisp-mode/basic-movement/npsrfb
index 2aca5dc..e03b713 100644
--- a/test/tests/emacs-lisp-mode/basic-movement/npsrfb
+++ b/test/tests/emacs-lisp-mode/basic-movement/npsrfb
@@ -6,5 +6,5 @@ Following line here
 
 ;;;;
 
-Testing |<l>ine here
+Testing |<line> here
 Following line here



reply via email to

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