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

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

[elpa] externals/objed 9225e77 194/216: Improve objed-extend


From: Stefan Monnier
Subject: [elpa] externals/objed 9225e77 194/216: Improve objed-extend
Date: Tue, 8 Jan 2019 12:29:37 -0500 (EST)

branch: externals/objed
commit 9225e77b467d058879631ac8ba90b58ea77d2b96
Author: Clemera <address@hidden>
Commit: Clemera <address@hidden>

    Improve objed-extend
---
 objed-objects.el | 12 ++++++++++--
 objed.el         | 33 ++++++++++++++++++++++-----------
 2 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/objed-objects.el b/objed-objects.el
index bb52b68..e69d0e9 100644
--- a/objed-objects.el
+++ b/objed-objects.el
@@ -400,6 +400,12 @@ OBJ is the object to use and defaults to 
`objed--current-obj'."
   (let ((obj (or obj objed--current-obj)))
     (objed--apply #'max obj)))
 
+(defun objed--basic-p ()
+  "Return non-nil if current object is a basic object.
+
+From basic objects `objed' starts expanding to context objects."
+  (memq objed--object '(line word char region buffer)))
+
 (defun objed--current (&optional obj)
   "Get the current range of interest.
 
@@ -409,8 +415,10 @@ otherwise the its the head of object OBJ which defaults to
   (let ((obj (or obj objed--current-obj)))
     (cond ((region-active-p)
            (list (region-beginning)
-                 (max (objed--end)
-                      (region-end))))
+                 (if (objed--basic-p)
+                     (region-end)
+                   (max (objed--end)
+                        (region-end)))))
           (t
            (car obj)))))
 
diff --git a/objed.el b/objed.el
index 798b6dd..296eb52 100644
--- a/objed.el
+++ b/objed.el
@@ -562,6 +562,23 @@ BEFORE and AFTER are forms to execute before/after calling 
the command."
      (objed--switch-to ',obj)))
 
 
+(defun objed--forward-word ()
+    (interactive)
+    (if (and (eq last-command 'objed-extend)
+             (eq objed--object 'word)
+             (looking-at "\\<"))
+        (objed-exchange-point-and-mark)
+      (call-interactively 'forward-word)))
+
+(defun objed--backward-word ()
+  (interactive)
+  (if (and (eq last-command 'objed-extend)
+           (eq objed--object 'word)
+           (looking-back "\\>" 1))
+      (objed-exchange-point-and-mark)
+    (call-interactively 'backward-word)))
+
+
 (defvar objed-map
   (let ((map (make-sparse-keymap)))
     ;; block unused chars by default
@@ -610,11 +627,10 @@ BEFORE and AFTER are forms to execute before/after 
calling the command."
     (define-key map "F" 'objed-move-char-forward)
 
     (define-key map "s" (objed--call-and-switch
-                         forward-word word
-                         (when (and (eq last-command 'objed-extend)
-                                    (looking-at "\\<"))
-                           (objed-exchange-point-and-mark))))
-    (define-key map "r" (objed--call-and-switch backward-word word))
+                         objed--forward-word
+                         word))
+    (define-key map "r" (objed--call-and-switch
+                         objed--backward-word word))
 
     (define-key map "S" 'objed-move-word-forward)
     (define-key map "R" 'objed-move-word-backward)
@@ -1479,11 +1495,6 @@ Skips strings and comments."
 (defvar objed--context-objects '(string bracket tag comment)
   "List of objects to be choosen by context.")
 
-(defun objed--basic-p ()
-  "Return non-nil if current object is a basic object.
-
-From basic objects `objed' starts expanding to context objects."
-  (memq objed--object '(line word char region buffer)))
 
 (defun objed--get-context-state (from)
   "Get state to be used by expand commands.
@@ -1720,7 +1731,7 @@ movement commands."
       (setq objed--extend-cookie
             (face-remap-add-relative 'objed-hl
                                      'objed-extend)))
-    (unless (= (point) (objed--end))
+    (when (< (objed--beg) (point) (objed--end))
       (goto-char (objed--beg)))
     (push-mark (if (or (>= (point) (objed--end))
                        (eq objed--object 'char))



reply via email to

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