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

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

[elpa] externals/objed 8a74424 125/216: Optimize init/reset procedure, a


From: Stefan Monnier
Subject: [elpa] externals/objed 8a74424 125/216: Optimize init/reset procedure, avoid unnecessary re-initialization
Date: Tue, 8 Jan 2019 12:29:24 -0500 (EST)

branch: externals/objed
commit 8a7442463f3201770e529e012e6613ec513fbd28
Author: Clemera <address@hidden>
Commit: Clemera <address@hidden>

    Optimize init/reset procedure, avoid unnecessary re-initialization
---
 objed.el      | 42 ++++++++++++++++++++++--------------------
 test/tests.el |  5 +++++
 2 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/objed.el b/objed.el
index b73f43d..09a0734 100644
--- a/objed.el
+++ b/objed.el
@@ -297,21 +297,24 @@ See also `objed-disabled-p'"
     (backward-paragraph . paragraph)
     (forward-paragraph . paragraph)
     (fill-paragraph . textblock)
-    (down-list string symbol word)
-    (forward-sexp sexp defun bracket string symbol word)
-    (backward-sexp sexp defun bracket string symbol word)
-    (indent-pp-sexp bracket sexp)
+    ;; TODO: add list object
+    ;; or recognize sexp type
+    ;; improve sexp nav...
+    (down-list . sexp)
+    (backward-up-list . sexp)
+    (up-list . sexp)
+    (forward-sexp . sexp)
+    (backward-sexp . sexp)
+    (indent-pp-sexp . bracket)
     ;; just use inner line?
     ;; TODO: on second press check all these:
     ;;section defun bracket string line)
-    (back-to-indentation . (line . inner))
+    (back-to-indentation . line)
     (org-beginning-of-line . line)
     (org-end-of-line . line)
     (backward-sentence . sentence)
     (org-backward-sentence . sentence)
     (org-backward-element . paragraph)
-    (backward-up-list bracket string)
-    (up-list bracket string)
     (beginning-of-defun . defun)
     (end-of-defun . defun)
     (outline-previous-visible-heading . section)
@@ -332,16 +335,9 @@ See also `objed-disabled-p'"
     (yank . region)
     (yank-pop . region)
     ;; misc
-    ;; TODO: find a way that doesnt need to reinit each time
     (which-key-C-h-dispatch . char)
     )
-  "Entry commands and associated objects.
-
-If the `cdr' of an entry is a list, each of the objects in this
-list is tried and the first that matches (:atp returns non-nil)
-will be used for initialization. If the `cdr' is a cons cell use
-the `cdr' of it as initial object state which defaults to `whole'
-otherwise."
+  "Entry commands and associated objects."
   :group 'objed
   :type '(alist :key-type sexp
                 :value-type (choice sexp
@@ -1104,6 +1100,8 @@ See `objed-cmd-alist'."
              (not objed--block-p)
              (eq real-this-command cmd)
              (not objed-disabled-p)
+             (not (eq (cadr overriding-terminal-local-map)
+                      objed-map))
              ;; (memq (key-binding "q")
              ;;            '(self-insert-command
              ;;              outshine-self-insert-command
@@ -1225,11 +1223,15 @@ mode line hint is removed again."
 
 Reinitializes the current object in case the current command is
 one of `objed-keeper-commands'."
-  (or (commandp (lookup-key objed-map (this-command-keys-vector)))
-       (and (memq (key-binding (this-command-keys-vector))
-                  objed-keeper-commands)
-            (prog1 #'ignore
-              (add-hook 'post-command-hook 'objed--reinit-object-one-time nil 
t)))))
+  (let ((ocmd (lookup-key objed-map (this-command-keys-vector)))
+        (o nil))
+    (or (commandp ocmd)
+        (and (or (memq this-command objed-keeper-commands)
+                 (and (setq o (cdr (assq this-command objed-cmd-alist)))
+                      (symbolp o)
+                      (setq objed--object o)))
+             (prog1 #'ignore
+               (add-hook 'post-command-hook 'objed--reinit-object-one-time nil 
t))))))
 
 
 (defun objed--reinit-object-one-time ()
diff --git a/test/tests.el b/test/tests.el
index 3b9b1cb..e21cbb0 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -13,7 +13,12 @@
     (setq this-command cmd)
     ;; pre command hook...
     (funcall #'objed--push-state)
+    (objed--keep-transient-p)
     (call-interactively cmd)
+    ;; post command hook
+    (when (memq 'objed--reinit-object-one-time
+                post-command-hook)
+      (objed--reinit-object-one-time))
     (setq last-command cmd)))
 
 (defun objed-decode-keysequence (str)



reply via email to

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