[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/objed 192217a 066/216: Add no-skip option and block obj
From: |
Stefan Monnier |
Subject: |
[elpa] externals/objed 192217a 066/216: Add no-skip option and block object |
Date: |
Tue, 8 Jan 2019 12:29:13 -0500 (EST) |
branch: externals/objed
commit 192217a9a1a5943b27453be400b4142e0fafc787
Author: Clemera <address@hidden>
Commit: Clemera <address@hidden>
Add no-skip option and block object
---
objed-objects.el | 59 ++++++++++++++++++++++++++++++++++++++++++--------------
objed.el | 33 +++++++++++++++++++++++--------
2 files changed, 70 insertions(+), 22 deletions(-)
diff --git a/objed-objects.el b/objed-objects.el
index bcc07c1..a377361 100644
--- a/objed-objects.el
+++ b/objed-objects.el
@@ -90,20 +90,20 @@ there is no object at point the code should return nil.
:try-next (optional)
-Code to run which moves point to the next available object. The
-code can assume it runs after point is moved out to the end of
-the current one if any. This will called until :get-obj returns
-non-nil. To indicate that search needs to be stopped, throw an
-error.
+Code to run which moves point to the next available object.
+If :no-skip is not set the code can assume it runs after point is
+moved out to the end of the current one if any. This will get
+called until :get-obj returns non-nil. To indicate that search
+needs to be stopped, throw an error.
:try-prev (optional)
Code to run which moves point to the previous available object.
-The code can assume it runs after point is moved out to the
-beginning of the current one if any. This will called
-until :get-obj returns non-nil. To indicate that search needs to
-be stopped, throw an error.
+The code can assume it runs after point is moved to the beginning
+of the current one if any. This will get called until :get-obj
+returns non-nil. To indicate that search needs to be stopped,
+throw an error.
:mode (optional)
@@ -111,15 +111,21 @@ Object defintions which don't use this keyword apply to
all
modes. If given it should be a symbol of a `major-mode'. Any
keyword definitions used for this object will then override the
default ones when in this mode. Keywords not used fallback to use
-the general definition."
+the general definition.
+
+:no-skip (optional)
+
+If this keyword is provided with a non-nil value, the current object
+is not skipped before search for the next one via :try-next."
(declare (indent 2))
(let* ((mode (plist-get args :mode))
+ (noskip (plist-get args :no-skip))
(fname (if mode
(intern (format "objed-%s-%s-object" name mode))
(intern (format "objed-%s-object" name))))
(args (objed--get-arg-plist
args
- '(:mode :atp :ref :get-obj :try-next :try-prev)))
+ '(:mode :no-skip :atp :ref :get-obj :try-next :try-prev)))
(arg (make-symbol "arg"))
(cbody nil)
(doc (format "%s object." (capitalize (symbol-name name))))
@@ -160,12 +166,16 @@ the general definition."
cbody))
(cond (mode
+ (when noskip
+ (put `,fname 'objed-no-skip t))
;; catch all return arg if not present
(push `(t ,arg) cbody)
`(defun ,fname (,arg)
,doc
(cond ,@(nreverse cbody))))
(t
+ (when noskip
+ (put `,fname 'objed-no-skip t))
(let ((res (list 'progn)))
(when key
(push `(define-key objed-object-map
@@ -588,7 +598,9 @@ If FROM is a position search from there otherwise search
starts
from end of object FROM."
(let ((obj (or from objed--current-obj)))
(save-excursion
- (when obj
+ (when (and obj
+ (not (get (objed--name2func objed--object)
+ 'objed-no-skip)))
(if (integer-or-marker-p obj)
(goto-char obj)
(goto-char (objed--max obj))))
@@ -1199,7 +1211,7 @@ property list where each key has an associated progn."
(let* ((keyw (pop keylst))
(vkeyw (and keyw (keywordp keyw) (memq keyw valid) keyw))
forms)
- (cond ((eq vkeyw :mode)
+ (cond ((memq vkeyw '(:mode :no-skip))
;; skip
(objed--get-arg-plist (cdr keylst) valid wrapped))
(vkeyw
@@ -2024,11 +2036,30 @@ non-nil the indentation block can contain empty lines."
:try-prev
(comint-previous-prompt 1))
+(objed-define-object nil block
+ :get-obj nil)
+
(with-eval-after-load 'python
+ ;; TODO: add this to macro functionality
+ (objed--install-advices
+ '((python-nav-backward-block . block)
+ (python-nav-forward-block . block)))
(objed-define-object nil defun
:mode python-mode
:get-obj
- (objed-bounds-from-region-cmd #'mark-defun)))
+ (objed-bounds-from-region-cmd #'mark-defun))
+ (objed-define-object nil block
+ :mode python-mode
+ :commands
+ :no-skip t
+ :try-next
+ (python-nav-forward-block)
+ :try-prev
+ (python-nav-backward-block)
+ :get-obj
+ (let ((start (save-excursion (python-nav-beginning-of-block) (point)))
+ (end (save-excursion (python-nav-end-of-block))))
+ (cons start end))))
(provide 'objed-objects)
;;; objed-objects.el ends here
diff --git a/objed.el b/objed.el
index 257c5e9..20d55f5 100644
--- a/objed.el
+++ b/objed.el
@@ -267,14 +267,30 @@ setting the user options
`objed-use-which-key-if-available-p' and
(require 'which-key nil t))
objed--avy-avail-p (when objed-use-avy-if-available-p
(require 'avy nil t)))
- (dolist (cmd2obj objed-cmd-alist)
- (advice-add (car cmd2obj) :after
- (apply-partially #'objed--activate (car cmd2obj)))
- (advice-add (car cmd2obj) :before 'objed--save-start-position)))
- (dolist (cmd2obj objed-cmd-alist)
- (advice-remove (car cmd2obj)
- (apply-partially #'objed--activate (car cmd2obj)))
- (advice-remove (car cmd2obj) 'objed--save-start-position))))
+ (objed--install-advices objed-cmd-alist t))
+ (objed--remove-advices objed-cmd-alist t)))
+
+
+(defun objed--install-advices (alist &optional do-not-save)
+ "Install advices according to ALIST.
+
+If DO-NOT-SAVE is non-nil don't store ALIST entries in
+`objed-cmd-alist'."
+ (dolist (cmd2obj alist)
+ (unless do-not-save (push cmd2obj objed-cmd-alist))
+ (advice-add (car cmd2obj) :after
+ (apply-partially #'objed--activate (car cmd2obj)))
+ (advice-add (car cmd2obj) :before 'objed--save-start-position)))
+
+(defun objed--remove-advices (alist)
+ "Remove advices accroding to ALIST.
+
+See `objed-cmd-alist'."
+ (dolist (cmd2obj alist)
+ (advice-remove (car cmd2obj)
+ (apply-partially #'objed--activate (car cmd2obj)))
+ (advice-remove (car cmd2obj) 'objed--save-start-position)))
+
;; * Customization
@@ -722,6 +738,7 @@ object as an argument."
(define-key map "w" 'objed-copy)
(define-key map "d" 'objed-delete)
(define-key map (kbd "DEL") 'objed-del-insert)
+ (define-key map (kbd "<backspace>") 'objed-del-insert)
(define-key map "y" 'objed-yank)
- [elpa] externals/objed 72053b7 109/216: Simplify macro usage again, (continued)
- [elpa] externals/objed 72053b7 109/216: Simplify macro usage again, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 9558b39 098/216: Add ace char object, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 49082c7 167/216: Accept 1 as universal arg, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 185fe41 111/216: Remove unused lexical var, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 8a74424 125/216: Optimize init/reset procedure, avoid unnecessary re-initialization, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 9c1b350 067/216: Update link, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 7abf5b3 091/216: Fixes #3, switch to remote object with '#', Stefan Monnier, 2019/01/08
- [elpa] externals/objed 7ba5cb2 088/216: New until beg/end of buffer behavior, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 22392cf 099/216: Add whitepsace objects, fixes #2, Stefan Monnier, 2019/01/08
- [elpa] externals/objed f3efa0e 121/216: Don't let sentence object jump over to next comments/string, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 192217a 066/216: Add no-skip option and block object,
Stefan Monnier <=
- [elpa] externals/objed a2df7ab 075/216: Stay active when using describe key in modal state, Stefan Monnier, 2019/01/08
- [elpa] externals/objed b7fbf71 106/216: Fixes #12, collect no-skipping objects correctly, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 29bccb0 042/216: Whitespace cleanup, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 2e1e5c1 110/216: Run compilation as part of make test, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 433e92d 104/216: Block objed advices in object body codes, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 79ec8af 116/216: Fix boundary error, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 5a1c9f7 122/216: Improve char switching with objec-ace, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 38887bb 107/216: Adjust textblock object, Stefan Monnier, 2019/01/08
- [elpa] externals/objed fc11d2b 119/216: Fix skipping ws if point is after the object, Stefan Monnier, 2019/01/08
- [elpa] externals/objed d50117d 114/216: Fix kill-op error, Stefan Monnier, 2019/01/08