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

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

[elpa] externals/objed 94436f0 6/9: Fallback to previous object if no ne


From: Clemens Radermacher
Subject: [elpa] externals/objed 94436f0 6/9: Fallback to previous object if no next found
Date: Sun, 24 Mar 2019 19:51:46 -0400 (EDT)

branch: externals/objed
commit 94436f0924e6ade551af2b9832312b17eb16754c
Author: Clemens Radermacher <address@hidden>
Commit: Clemens Radermacher <address@hidden>

    Fallback to previous object if no next found
---
 objed-objects.el | 22 +++++++++++++++++++---
 objed.el         |  6 +++---
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/objed-objects.el b/objed-objects.el
index 2115acf..76d8c7c 100644
--- a/objed-objects.el
+++ b/objed-objects.el
@@ -967,9 +967,25 @@ STATE is the state for the object and defaults to whole. 
If ODATA
 is non-nil it is used as object position data, otherwise
 calculate the data of the object at current position using
 `objed--get'."
-  (setq objed--object o)
-  (setq objed--obj-state (or state 'whole))
-  (setq objed--current-obj (or odata (objed--get))))
+  (let ((odata (let* ((objed--object o)
+                      (objed--obj-state (or state 'whole))
+                      (tryb t))
+                 (or odata
+                     ;; FIXME: all default objects should throw an error
+                     ;; if try-next, try-prev fails.
+                     (condition-case nil
+                         (or (objed--get)
+                             (setq tryb nil)
+                             (objed--get t))
+                       (error
+                        (when tryb
+                          (objed--get t))))))))
+    (if odata
+        (setq objed--object o
+              objed--obj-state (or state 'whole)
+              objed--current-obj odata)
+      (prog1 nil
+        (message "No %s found." o)))))
 
 
 (defun objed--distant-p (o)
diff --git a/objed.el b/objed.el
index 390ff40..4a558f2 100644
--- a/objed.el
+++ b/objed.el
@@ -1230,13 +1230,13 @@ or object position data."
   ;; if anything went wrong make sure to start with clean state
   (when objed--buffer
     (objed--reset))
-  ;; (unless objed--buffer
-  (setq objed--current-obj nil)
-  (setq objed--obj-state 'whole)
 
+  ;; (setq objed--current-obj nil)
+  ;; (setq objed--obj-state 'whole)
   (setq objed--buffer (current-buffer))
   (add-hook 'pre-command-hook 'objed--push-state nil t)
   (add-hook 'post-command-hook 'objed--check-buffer)
+
   (pcase-dolist
       (`(,var . ,val)
        `((hl-line-range-function . objed-hl-function)



reply via email to

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