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

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

[elpa] externals/ivy-posframe 8f62984 033/195: Add ivy-posframe-read-act


From: Feng Shu
Subject: [elpa] externals/ivy-posframe 8f62984 033/195: Add ivy-posframe-read-action and ivy-posframe-dispatching-done
Date: Sat, 3 Oct 2020 07:11:40 -0400 (EDT)

branch: externals/ivy-posframe
commit 8f6298494da7ae35cece906050bce4f099fb7ecb
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>

    Add ivy-posframe-read-action and ivy-posframe-dispatching-done
---
 README.md       | 37 ++++++++++++++++---------------
 ivy-posframe.el | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 83 insertions(+), 23 deletions(-)

diff --git a/README.md b/README.md
index ae75cea..ed8014c 100644
--- a/README.md
+++ b/README.md
@@ -1,21 +1,23 @@
+Note: this file is converted from ivy-posframe.el by 
[el2org](https://github.com/tumashu/el2org), please do not edit it by hand!!!
+
 
 # &#30446;&#24405;
 
-1.  [ivy-posframe README](#orgf04a3ef)
-    1.  [What is ivy-posframe](#org9bf1330)
-    2.  [Display functions](#orga76454a)
-    3.  [How to enable ivy-posframe](#org422a15a)
-    4.  [Tips](#org80ae3b7)
-        1.  [How to show fringe to ivy-posframe](#org1592d0f)
-        2.  [How to custom your ivy-posframe style](#org0aa3f21)
+1.  [ivy-posframe README](#orgcfa545c)
+    1.  [What is ivy-posframe](#org3c6ad89)
+    2.  [Display functions](#orgda8366d)
+    3.  [How to enable ivy-posframe](#org4d648e7)
+    4.  [Tips](#orgcef74d7)
+        1.  [How to show fringe to ivy-posframe](#org7a32697)
+        2.  [How to custom your ivy-posframe style](#org06a0215)
 
 
-<a id="orgf04a3ef"></a>
+<a id="orgcfa545c"></a>
 
 # ivy-posframe README
 
 
-<a id="org9bf1330"></a>
+<a id="org3c6ad89"></a>
 
 ## What is ivy-posframe
 
@@ -25,7 +27,7 @@ to show its candidate menu.
 NOTE: ivy-posframe requires Emacs 26
 
 
-<a id="orga76454a"></a>
+<a id="orgda8366d"></a>
 
 ## Display functions
 
@@ -41,13 +43,14 @@ NOTE: ivy-posframe requires Emacs 26
     ![img](./snapshots/ivy-posframe-display-at-point.gif)
 
 
-<a id="org422a15a"></a>
+<a id="org4d648e7"></a>
 
 ## How to enable ivy-posframe
 
 1.  Global mode
 
         (require 'ivy-posframe)
+        (ivy-posframe-setup)
         (setq ivy-display-function #'ivy-posframe-display)
         ;; (setq ivy-display-function #'ivy-posframe-display-at-frame-center)
         ;; (setq ivy-display-function #'ivy-posframe-display-at-window-center)
@@ -57,21 +60,23 @@ NOTE: ivy-posframe requires Emacs 26
 2.  Per-command mode.
 
         (require 'ivy-posframe)
+        (ivy-posframe-setup)
         ;; Different command can use different display function.
         (push '(counsel-M-x . ivy-posframe-display-at-window-bottom-left) 
ivy-display-functions-alist)
         (push '(complete-symbol . ivy-posframe-display-at-point) 
ivy-display-functions-alist)
 3.  Fallback mode
 
         (require 'ivy-posframe)
+        (ivy-posframe-setup)
         (push '(t . ivy-posframe-display) ivy-display-functions-alist)
 
 
-<a id="org80ae3b7"></a>
+<a id="orgcef74d7"></a>
 
 ## Tips
 
 
-<a id="org1592d0f"></a>
+<a id="org7a32697"></a>
 
 ### How to show fringe to ivy-posframe
 
@@ -83,7 +88,7 @@ By the way, User can set **any** parameters of ivy-posframe 
with
 the help of \`ivy-posframe-parameters'.
 
 
-<a id="org0aa3f21"></a>
+<a id="org06a0215"></a>
 
 ### How to custom your ivy-posframe style
 
@@ -92,7 +97,3 @@ The simplest way is:
     (defun ivy-posframe-display-at-XXX (str)
       (ivy-posframe--display str #'your-own-poshandler-function))
     (ivy-posframe-setup) ; This line is needed.
-
-
-
-Converted from ivy-posframe.el by [el2org](https://github.com/tumashu/el2org) .
\ No newline at end of file
diff --git a/ivy-posframe.el b/ivy-posframe.el
index 63a9f7a..4ca9fb9 100644
--- a/ivy-posframe.el
+++ b/ivy-posframe.el
@@ -51,6 +51,7 @@
 ;; 1. Global mode
 ;;    #+BEGIN_EXAMPLE
 ;;    (require 'ivy-posframe)
+;;    (ivy-posframe-setup)
 ;;    (setq ivy-display-function #'ivy-posframe-display)
 ;;    ;; (setq ivy-display-function #'ivy-posframe-display-at-frame-center)
 ;;    ;; (setq ivy-display-function #'ivy-posframe-display-at-window-center)
@@ -61,6 +62,7 @@
 ;; 2. Per-command mode.
 ;;    #+BEGIN_EXAMPLE
 ;;    (require 'ivy-posframe)
+;;    (ivy-posframe-setup)
 ;;    ;; Different command can use different display function.
 ;;    (push '(counsel-M-x . ivy-posframe-display-at-window-bottom-left) 
ivy-display-functions-alist)
 ;;    (push '(complete-symbol . ivy-posframe-display-at-point) 
ivy-display-functions-alist)
@@ -68,6 +70,7 @@
 ;; 3. Fallback mode
 ;;    #+BEGIN_EXAMPLE
 ;;    (require 'ivy-posframe)
+;;    (ivy-posframe-setup)
 ;;    (push '(t . ivy-posframe-display) ivy-display-functions-alist)
 ;;    #+END_EXAMPLE
 
@@ -127,6 +130,10 @@ When nil, Using current frame's font as fallback."
 (defvar ivy-posframe-buffer " *ivy-posframe-buffer*"
   "The posframe-buffer used by ivy-posframe.")
 
+(defvar ivy-posframe--ignore-prompt nil
+  "When non-nil, ivy-posframe will ignore prompt.
+This variable is useful for `ivy-posframe-read-action' .")
+
 ;; Fix warn
 (defvar emacs-basic-display)
 
@@ -139,8 +146,10 @@ When nil, Using current frame's font as fallback."
        ivy-posframe-buffer
        :font ivy-posframe-font
        :string
-       (with-current-buffer (get-buffer-create " *Minibuf-1*")
-         (concat (buffer-string) "  " str))
+       (if ivy-posframe--ignore-prompt
+           str
+         (with-current-buffer (get-buffer-create " *Minibuf-1*")
+           (concat (buffer-string) "  " str)))
        :position (point)
        :poshandler poshandler
        :background-color (face-attribute 'ivy-posframe :background)
@@ -191,17 +200,67 @@ When nil, Using current frame's font as fallback."
                 (not (display-graphic-p))))))
 
 (defun ivy-posframe-setup ()
-  "Regedit all display functions of ivy-posframe to 
`ivy-display-functions-props'."
+  "Setup ivy-posframe."
   (interactive)
+  ;; Regedit all display functions of ivy-posframe
+  ;; to `ivy-display-functions-props'.
   (mapatoms
    #'(lambda (func)
        (when (and (functionp func)
                   (string-match-p "^ivy-posframe-display" (symbol-name func))
                   (not (assq func ivy-display-functions-props)))
          (push `(,func :cleanup ivy-posframe-cleanup)
-               ivy-display-functions-props)))))
+               ivy-display-functions-props))))
+  ;; Re-configure ivy keymap.
+  (define-key ivy-minibuffer-map (kbd "C-M-a") 'ivy-posframe-read-action)
+  (define-key ivy-minibuffer-map (kbd "M-o") 'ivy-posframe-dispatching-done))
+
+(defun ivy-posframe-dispatching-done ()
+  "Select one of the available actions and call `ivy-done'."
+  (interactive)
+  (when (ivy-posframe-read-action)
+    (ivy-done)))
+
+(defun ivy-posframe-read-action ()
+  "Change the action to one of the available ones.
+
+Return nil for `minibuffer-keyboard-quit' or wrong key during the
+selection, non-nil otherwise."
+  (interactive)
+  (let* ((actions (ivy-state-action ivy-last))
+         (caller (ivy-state-caller ivy-last))
+         (display-function
+          (or ivy-display-function
+              (cdr (or (assq caller ivy-display-functions-alist)
+                       (assq t ivy-display-functions-alist))))))
+    (if (not (ivy--actionp actions))
+        t
+      (let* ((hint (funcall ivy-read-action-format-function (cdr actions)))
+             (resize-mini-windows t)
+             (key "")
+             action-idx)
+        (while (and (setq action-idx (cl-position-if
+                                      (lambda (x)
+                                        (string-prefix-p key (car x)))
+                                      (cdr actions)))
+                    (not (string= key (car (nth action-idx (cdr actions))))))
+          (setq key (concat key (string
+                                 (read-key
+                                  (if (functionp display-function)
+                                      (let ((ivy-posframe--ignore-prompt t))
+                                        (funcall display-function hint)
+                                        "Please type a key: ")
+                                    hint))))))
+        (cond ((member key '("" ""))
+               nil)
+              ((null action-idx)
+               (message "%s is not bound" key)
+               nil)
+              (t
+               (message "")
+               (setcar actions (1+ action-idx))
+               (ivy-set-action actions)))))))
 
-(ivy-posframe-setup)
 
 (provide 'ivy-posframe)
 



reply via email to

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