[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ivy-posframe 9872f35 135/195: Merge pull request #43 fr
From: |
Feng Shu |
Subject: |
[elpa] externals/ivy-posframe 9872f35 135/195: Merge pull request #43 from conao3/ivy-posframe-mode |
Date: |
Sat, 3 Oct 2020 07:12:00 -0400 (EDT) |
branch: externals/ivy-posframe
commit 9872f35bad0d6b6f8e30b9c72b95b827cae5a2ed
Merge: b1ecab7 7e33255
Author: tumashu <tumashu@163.com>
Commit: GitHub <noreply@github.com>
Merge pull request #43 from conao3/ivy-posframe-mode
Ivy-posframe now minor-mode
---
README.md | 107 ++++++++++++++++++-----------
ivy-posframe.el | 209 +++++++++++++++++++++++++++++++++++++++-----------------
2 files changed, 212 insertions(+), 104 deletions(-)
diff --git a/README.md b/README.md
index f14f57c..55d9787 100644
--- a/README.md
+++ b/README.md
@@ -1,26 +1,25 @@
Note: this file is auto converted from ivy-posframe.el by
[el2org](https://github.com/tumashu/el2org), please do not edit it by hand!!!
-# 目录
+# Table of Contents
-1. [ivy-posframe README](#orgf13cc66)
- 1. [What is ivy-posframe](#orgbd4ba62)
- 2. [Display functions](#orge8456a3)
- 3. [How to enable ivy-posframe](#orge72596b)
- 1. [Global mode](#org359004f)
- 2. [Per-command mode.](#orgdfd4dbf)
- 3. [Fallback mode](#org589575f)
- 4. [Tips](#orgd8d788b)
- 1. [How to show fringe to ivy-posframe](#org44b1a57)
- 2. [How to custom your ivy-posframe style](#org2e4b09d)
+1. [ivy-posframe README](#orgb29527d)
+ 1. [What is ivy-posframe](#org73ec970)
+ 2. [Display functions](#org7dc9307)
+ 3. [How to enable ivy-posframe](#org491e830)
+ 1. [Global mode](#org38e37cf)
+ 2. [Per-command mode.](#org89e4db4)
+ 4. [Tips](#org2af7073)
+ 1. [How to show fringe to ivy-posframe](#orgc0851d4)
+ 2. [How to custom your ivy-posframe style](#orgdab58bc)
-<a id="orgf13cc66"></a>
+<a id="orgb29527d"></a>
# ivy-posframe README
-<a id="orgbd4ba62"></a>
+<a id="org73ec970"></a>
## What is ivy-posframe
@@ -31,7 +30,7 @@ NOTE: ivy-posframe requires Emacs 26 and do not support mouse
click.
-<a id="orge8456a3"></a>
+<a id="org7dc9307"></a>
## Display functions
@@ -47,35 +46,69 @@ click.
![img](./snapshots/ivy-posframe-display-at-point.png)
-<a id="orge72596b"></a>
+<a id="org491e830"></a>
## How to enable ivy-posframe
-<a id="org359004f"></a>
+<a id="org38e37cf"></a>
### Global mode
(require 'ivy-posframe)
- (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)
- ;; (setq ivy-display-function #'ivy-posframe-display-at-frame-bottom-left)
- ;; (setq ivy-display-function #'ivy-posframe-display-at-window-bottom-left)
- ;; (setq ivy-display-function #'ivy-posframe-display-at-point)
- (ivy-posframe-enable)
+ ;; display at `ivy-posframe-style'
+ (setq ivy-posframe-display-functions-alist '((t . ivy-posframe-display)))
+ ;; (setq ivy-posframe-display-functions-alist '((t .
ivy-posframe-display-at-frame-center)))
+ ;; (setq ivy-posframe-display-functions-alist '((t .
ivy-posframe-display-at-window-center)))
+ ;; (setq ivy-posframe-display-functions-alist '((t .
ivy-posframe-display-at-frame-bottom-left)))
+ ;; (setq ivy-posframe-display-functions-alist '((t .
ivy-posframe-display-at-window-bottom-left)))
+ (ivy-posframe-mode t)
-<a id="orgdfd4dbf"></a>
+<a id="org89e4db4"></a>
### Per-command mode.
(require 'ivy-posframe)
;; 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)
- (push '(swiper . ivy-posframe-display-at-point)
ivy-display-functions-alist)
- (ivy-posframe-enable)
+ (setq ivy-posframe-display-functions-alist
+ '((swiper . ivy-posframe-display-at-point)
+ (complete-symbol . ivy-posframe-display-at-point)
+ (counsel-M-x . ivy-posframe-display-at-window-bottom-left)
+ (t . ivy-posframe-display)))
+ (ivy-posframe-mode t)
+
+You can use ivy original display function on specify function.
+You may want to use the original display function because display
+of Swiper at point hides the contents of the buffer.
+
+ (require 'ivy-posframe)
+ ;; Different command can use different display function.
+ (setq ivy-posframe-display-functions-alist
+ '((swiper . nil)
+ (complete-symbol . ivy-posframe-display-at-point)
+ (counsel-M-x . ivy-posframe-display-at-window-bottom-left)
+ (t . ivy-posframe-display)))
+ (ivy-posframe-mode t)
+
+You may want to change the height of ivy by a function only while
+using posframe. This is possible with the code below.
+
+The following example displays swiper on 20 lines by default for ivy,
+and displays other functions in posframe at the location specified on
+40 lines.
+
+ (require 'ivy-posframe)
+ ;; Different command can use different display function.
+ (setq ivy-posframe-height-alist '((swiper . 20)
+ (t . 40)))
+
+ (setq ivy-posframe-display-functions-alist
+ '((swiper . nil)
+ (complete-symbol . ivy-posframe-display-at-point)
+ (counsel-M-x . ivy-posframe-display-at-window-bottom-left)
+ (t . ivy-posframe-display)))
+ (ivy-posframe-mode t)
NOTE: Using swiper as example: swiper's display function **only**
take effect when you call swiper command with global keybinding, if
@@ -88,21 +121,12 @@ by ivy to find display function in
\`ivy-display-functions-alist',
"C-h v this-command" is a good idea.
-<a id="org589575f"></a>
-
-### Fallback mode
-
- (require 'ivy-posframe)
- (push '(t . ivy-posframe-display) ivy-display-functions-alist)
- (ivy-posframe-enable)
-
-
-<a id="orgd8d788b"></a>
+<a id="org2af7073"></a>
## Tips
-<a id="org44b1a57"></a>
+<a id="orgc0851d4"></a>
### How to show fringe to ivy-posframe
@@ -114,7 +138,7 @@ By the way, User can set **any** parameters of ivy-posframe
with
the help of \`ivy-posframe-parameters'.
-<a id="org2e4b09d"></a>
+<a id="orgdab58bc"></a>
### How to custom your ivy-posframe style
@@ -122,5 +146,6 @@ The simplest way is:
(defun ivy-posframe-display-at-XXX (str)
(ivy-posframe--display str #'your-own-poshandler-function))
- (ivy-posframe-enable) ; This line is needed.
+ (push 'ivy-posframe-display-at-XXX ivy-posframe-display-function-list) ;
This line is needed.
+ (ivy-posframe-mode t) ; This line is needed.
diff --git a/ivy-posframe.el b/ivy-posframe.el
index 7628e24..5d75fe6 100644
--- a/ivy-posframe.el
+++ b/ivy-posframe.el
@@ -54,22 +54,58 @@
;; *** Global mode
;; #+BEGIN_EXAMPLE
;; (require 'ivy-posframe)
-;; (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)
-;; ;; (setq ivy-display-function #'ivy-posframe-display-at-frame-bottom-left)
-;; ;; (setq ivy-display-function #'ivy-posframe-display-at-window-bottom-left)
-;; ;; (setq ivy-display-function #'ivy-posframe-display-at-point)
-;; (ivy-posframe-enable)
+;; ;; display at `ivy-posframe-style'
+;; (setq ivy-posframe-display-functions-alist '((t . ivy-posframe-display)))
+;; ;; (setq ivy-posframe-display-functions-alist '((t .
ivy-posframe-display-at-frame-center)))
+;; ;; (setq ivy-posframe-display-functions-alist '((t .
ivy-posframe-display-at-window-center)))
+;; ;; (setq ivy-posframe-display-functions-alist '((t .
ivy-posframe-display-at-frame-bottom-left)))
+;; ;; (setq ivy-posframe-display-functions-alist '((t .
ivy-posframe-display-at-window-bottom-left)))
+;; (ivy-posframe-mode t)
;; #+END_EXAMPLE
;; *** Per-command mode.
;; #+BEGIN_EXAMPLE
;; (require 'ivy-posframe)
;; ;; 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)
-;; (push '(swiper . ivy-posframe-display-at-point) ivy-display-functions-alist)
-;; (ivy-posframe-enable)
+;; (setq ivy-posframe-display-functions-alist
+;; '((swiper . ivy-posframe-display-at-point)
+;; (complete-symbol . ivy-posframe-display-at-point)
+;; (counsel-M-x . ivy-posframe-display-at-window-bottom-left)
+;; (t . ivy-posframe-display)))
+;; (ivy-posframe-mode t)
+;; #+END_EXAMPLE
+;;
+;; You can use ivy original display function on specify function.
+;; You may want to use the original display function because display
+;; of Swiper at point hides the contents of the buffer.
+;; #+BEGIN_EXAMPLE
+;; (require 'ivy-posframe)
+;; ;; Different command can use different display function.
+;; (setq ivy-posframe-display-functions-alist
+;; '((swiper . nil)
+;; (complete-symbol . ivy-posframe-display-at-point)
+;; (counsel-M-x . ivy-posframe-display-at-window-bottom-left)
+;; (t . ivy-posframe-display)))
+;; (ivy-posframe-mode t)
+;; #+END_EXAMPLE
+;;
+;; You may want to change the height of ivy by a function only while
+;; using posframe. This is possible with the code below.
+;;
+;; The following example displays swiper on 20 lines by default for ivy,
+;; and displays other functions in posframe at the location specified on
+;; 40 lines.
+;; #+BEGIN_EXAMPLE
+;; (require 'ivy-posframe)
+;; ;; Different command can use different display function.
+;; (setq ivy-posframe-height-alist '((swiper . 20)
+;; (t . 40)))
+;;
+;; (setq ivy-posframe-display-functions-alist
+;; '((swiper . nil)
+;; (complete-symbol . ivy-posframe-display-at-point)
+;; (counsel-M-x . ivy-posframe-display-at-window-bottom-left)
+;; (t . ivy-posframe-display)))
+;; (ivy-posframe-mode t)
;; #+END_EXAMPLE
;;
;; NOTE: Using swiper as example: swiper's display function *only*
@@ -82,13 +118,6 @@
;; by ivy to find display function in `ivy-display-functions-alist',
;; "C-h v this-command" is a good idea.
-;; *** Fallback mode
-;; #+BEGIN_EXAMPLE
-;; (require 'ivy-posframe)
-;; (push '(t . ivy-posframe-display) ivy-display-functions-alist)
-;; (ivy-posframe-enable)
-;; #+END_EXAMPLE
-
;; ** Tips
;; *** How to show fringe to ivy-posframe
@@ -107,7 +136,8 @@
;; #+BEGIN_EXAMPLE
;; (defun ivy-posframe-display-at-XXX (str)
;; (ivy-posframe--display str #'your-own-poshandler-function))
-;; (ivy-posframe-enable) ; This line is needed.
+;; (push 'ivy-posframe-display-at-XXX ivy-posframe-display-function-list) ;
This line is needed.
+;; (ivy-posframe-mode t) ; This line is needed.
;; #+END_EXAMPLE
;;; Code:
@@ -168,6 +198,21 @@ When 0, no border is showed."
:group 'ivy-posframe
:type 'string)
+(defcustom ivy-posframe-height-alist nil
+ "The `ivy-height-alist' while working ivy-posframe."
+ :group 'ivy-posframe
+ :type 'sexp)
+
+(defcustom ivy-posframe-display-functions-alist '((t . ivy-posframe-display))
+ "The `ivy-display-functions-alist' while working ivy-posframe."
+ :group 'ivy-posframe
+ :type 'sexp)
+
+(defcustom ivy-posframe-additional-display-functions nil
+ "The additional display functions"
+ :group 'ivy-posframe
+ :type 'sexp)
+
(defface ivy-posframe
'((t (:inherit default)))
"Face used by the ivy-posframe."
@@ -191,13 +236,13 @@ When 0, no border is showed."
This variable is useful for `ivy-posframe-read-action' .")
(defvar ivy-posframe--display-p nil
- "The status of `ivy-posframe--display'")
+ "The status of `ivy-posframe--display'.")
;; Fix warn
(defvar emacs-basic-display)
(defun ivy-posframe--display (str &optional poshandler)
- "Show STR in ivy's posframe."
+ "Show STR in ivy's posframe with POSHANDLER."
(if (not (posframe-workable-p))
(ivy-display-function-fallback str)
(setq ivy-posframe--display-p t)
@@ -217,11 +262,11 @@ This variable is useful for `ivy-posframe-read-action' .")
:internal-border-width ivy-posframe-border-width
:internal-border-color (face-attribute 'ivy-posframe-border :background
nil t)
:override-parameters ivy-posframe-parameters))
- (ivy-posframe--add-prompt)))
+ (ivy-posframe--add-prompt 'ignore)))
(defun ivy-posframe-display (str)
- (let ((func (intern (format "ivy-posframe-display-at-%s"
- ivy-posframe-style))))
+ "Display STR via `posframe' by `ivy-posframe-style'."
+ (let ((func (intern (format "ivy-posframe-display-at-%s"
ivy-posframe-style))))
(if (functionp func)
(funcall func str)
(ivy-posframe-display-at-frame-bottom-left str))))
@@ -247,6 +292,14 @@ This variable is useful for `ivy-posframe-read-action' .")
(defun ivy-posframe-display-at-point (str)
(ivy-posframe--display str #'posframe-poshandler-point-bottom-left-corner))
+(defvar ivy-posframe-display-function-list '(ivy-posframe-display
+
ivy-posframe-display-at-window-center
+
ivy-posframe-display-at-frame-center
+
ivy-posframe-display-at-window-bottom-left
+
ivy-posframe-display-at-frame-bottom-left
+
ivy-posframe-display-at-frame-bottom-window-center
+ ivy-posframe-display-at-point))
+
(defun ivy-posframe-cleanup ()
"Cleanup ivy's posframe."
(when (posframe-workable-p)
@@ -259,19 +312,6 @@ This variable is useful for `ivy-posframe-read-action' .")
(when (ivy-posframe-read-action)
(ivy-done)))
-(defun ivy-posframe--add-prompt ()
- "Add the ivy prompt to the posframe."
- (unless ivy-posframe--ignore-prompt
- (with-current-buffer (window-buffer (active-minibuffer-window))
- (let ((point (point))
- (prompt (buffer-string)))
- (remove-text-properties 0 (length prompt) '(read-only nil) prompt)
- (with-current-buffer ivy-posframe-buffer
- (goto-char (point-min))
- (delete-region (point) (save-excursion (line-move 1 'noerror)
(point)))
- (insert prompt " \n")
- (add-text-properties point (1+ point) '(face
ivy-posframe-cursor)))))))
-
(defun ivy-posframe-read-action ()
"Change the action to one of the available ones.
@@ -413,10 +453,24 @@ selection, non-nil otherwise."
(ivy-quit-and-run
(avy-action-goto (avy-candidate-beg candidate)))))))
-(defun ivy-posframe--minibuffer-setup (orig-func)
- "Advice function of `ivy--minibuffer-setup'."
+;;; Variables
+
+(defvar ivy-posframe-display-function-list
+ (append ivy-posframe-additional-display-functions
ivy-posframe-display-function-list))
+
+(defvar ivy-posframe-advice-alist
+ '((ivy--minibuffer-setup . ivy-posframe--minibuffer-setup)
+ (ivy--queue-exhibit . ivy-posframe--add-prompt)
+ (ivy--display-function-prop . ivy-posframe--display-function-prop)
+ (ivy--height . ivy-posframe--height)
+ (ivy-read . ivy-posframe--read)))
+
+;;; Advice
+
+(defun ivy-posframe--minibuffer-setup (fn &rest args)
+ "Advice function of FN, `ivy--minibuffer-setup' with ARGS."
(let ((ivy-fixed-height-minibuffer nil))
- (funcall orig-func))
+ (apply fn args))
(when (and ivy-posframe-hide-minibuffer
;; only hide minibuffer's info when posframe is showed.
ivy-posframe--display-p)
@@ -427,36 +481,65 @@ selection, non-nil otherwise."
`(:background ,bg-color :foreground ,bg-color)))
(setq-local cursor-type nil))))
+(defun ivy-posframe--add-prompt (fn &rest args)
+ "Add the ivy prompt to the posframe. Advice FN with ARGS."
+ (apply fn args)
+ (unless ivy-posframe--ignore-prompt
+ (with-current-buffer (window-buffer (active-minibuffer-window))
+ (let ((point (point))
+ (prompt (buffer-string)))
+ (remove-text-properties 0 (length prompt) '(read-only nil) prompt)
+ (with-current-buffer ivy-posframe-buffer
+ (goto-char (point-min))
+ (delete-region (point) (save-excursion (line-move 1 'noerror)
(point)))
+ (insert prompt " \n")
+ (add-text-properties point (1+ point) '(face
ivy-posframe-cursor)))))))
+
+(defun ivy-posframe--display-function-prop (fn &rest args)
+ "Around advice of FN with ARGS."
+ (let ((ivy-display-functions-props
+ (append ivy-display-functions-props
+ (mapcar (lambda (elm) `(,elm :cleanup ivy-posframe-cleanup))
+ ivy-posframe-display-function-list))))
+ (apply fn args)))
+
+(defun ivy-posframe--height (fn &rest args)
+ "Around advide of FN with ARGS."
+ (let ((ivy-height-alist
+ (append ivy-posframe-height-alist ivy-height-alist)))
+ (apply fn args)))
+
+(defun ivy-posframe--read (fn &rest args)
+ "Around advice of FN with AGS."
+ (let ((ivy-display-functions-alist
+ (append ivy-posframe-display-functions-alist
ivy-display-functions-alist)))
+ (apply fn args)))
+
;;;###autoload
-(defun ivy-posframe-enable ()
- "Enable ivy-posframe."
- (interactive)
- (require 'ivy)
- ;; Add 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))))
- (define-key ivy-minibuffer-map
- [remap ivy-read-action] 'ivy-posframe-read-action)
- (define-key ivy-minibuffer-map
- [remap ivy-dispatching-done] 'ivy-posframe-dispatching-done)
- (define-key ivy-minibuffer-map [remap ivy-avy] 'ivy-posframe-avy)
- (define-key ivy-minibuffer-map [remap swiper-avy] 'ivy-posframe-swiper-avy)
- (advice-add 'ivy--minibuffer-setup :around #'ivy-posframe--minibuffer-setup)
- (advice-add 'ivy--queue-exhibit :after #'ivy-posframe--add-prompt)
- (message "ivy-posframe is enabled, disabling it need to reboot emacs."))
+(define-minor-mode ivy-posframe-mode
+ "Display ivy via posframe."
+ :init-value nil
+ :global t
+ :lighter " ivy-pf"
+ :group 'ivy-posframe
+ :keymap '(([remap ivy-read-action] ivy-posframe-read-action)
+ ([remap ivy-dispatching-done] ivy-posframe-dispatching-done)
+ ([remap ivy-avy] ivy-posframe-avy)
+ ([remap swiper-avy] ivy-posframe-swiper-avy))
+ (let ((advices ivy-posframe-advice-alist))
+ (if ivy-posframe-mode
+ (mapcar (lambda (elm) (advice-add (car elm) :around (cdr elm)))
advices)
+ (mapcar (lambda (elm) (advice-remove (car elm) (cdr elm))) advices))))
+
+;;;###autoload
+(defalias 'ivy-posframe-enable 'ivy-posframe-mode)
;;;###autoload
(defun ivy-posframe-demo ()
"Toggle a demo config of ivy-posframe.
This function is ONLY used to test ivy-posframe."
(interactive)
- (ivy-posframe-enable)
+ (ivy-posframe-mode t)
(let ((config '(t . ivy-posframe-display-at-frame-center)))
(if (member config ivy-display-functions-alist)
(progn
- [elpa] externals/ivy-posframe aadadf1 185/195: Merge pull request #73 from tttuuu888/work-issue-71-2, (continued)
- [elpa] externals/ivy-posframe aadadf1 185/195: Merge pull request #73 from tttuuu888/work-issue-71-2, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 85f2f7a 184/195: Fix for prompt line duplicated issue in another way. #71, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 61cb32e 192/195: Fix swiper-avy and ivy-posframe are having trouble #80, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe ad83ce5 189/195: Merge pull request #79 from xeijin/patch-1, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 4474956 194/195: let ivy-posframe-swiper-avy work when do not use ivy-posframe function, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 556c9a9 161/195: Check (display-graphic-p) dynamically in advices, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 46b4089 081/195: Merge pull request #33 from conao3/issue/remove-top-level-setup-executing, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe f5da408 157/195: remove ivy-display-function, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe c9a7331 143/195: handle ivy-display-function, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 45dc8ee 137/195: Remove ivy-posframe-demo, ivy-posframe-mode can do same job, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 9872f35 135/195: Merge pull request #43 from conao3/ivy-posframe-mode,
Feng Shu <=
- [elpa] externals/ivy-posframe 7e33255 134/195: not use macro, write all form, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 2a97933 155/195: Fix for `Error in post-command-hook ...`, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 7be71b6 126/195: fix align, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 3433b00 077/195: Merge pull request #29 from CeleritasCelery/recursive-fix, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe d13ad21 111/195: fix argument issue, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 8624418 123/195: add ivy-posframe--display-function-prop advice, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 4e95a48 108/195: fix display function declaration by display-functions-alist, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe d58350c 172/195: make ivy-posframe-buffer as defcustom variable and set setter, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 7f60e8c 112/195: define ivy-posframe-display-function-list, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe c654366 160/195: Merge pull request #51 from conao3/simplify-get-position, Feng Shu, 2020/10/03