Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the behavior of ivy-default-view-name customizable #3021

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions ivy.el
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ Set this to \"(%d/%d) \" to display both the index and the count."
(defcustom ivy-add-newline-after-prompt nil
"When non-nil, add a newline after the `ivy-read' prompt."
:type 'boolean)
(defcustom ivy-default-view-name-update-exist-p t
"When t, ivy-default-view-name will return the existing view name.
When nil, ivy-default-view-name will append a number as a suffix to make the view name unique."
:type 'boolean
:options '(t nil)
:group 'ivy)

(defcustom ivy-wrap nil
"When non-nil, wrap around after the first and the last candidate."
Expand Down Expand Up @@ -4308,7 +4314,7 @@ TREE is a nested list with the following valid cars:

TREE can be nested multiple times to have multiple window splits.")

(defun ivy-default-view-name ()
(cl-defun ivy-default-view-name (&key (update t))
"Return default name for new view."
(let* ((default-view-name
(concat "{} "
Expand All @@ -4327,19 +4333,20 @@ TREE can be nested multiple times to have multiple window splits.")
(regexp-quote default-view-name)
" \\([0-9]+\\)"))
old-view)
(cond ((setq old-view
(cl-find-if
(lambda (x)
(string-match view-name-re (car x)))
ivy-views))
(format "%s %d"
default-view-name
(1+ (string-to-number
(match-string 1 (car old-view))))))
((assoc default-view-name ivy-views)
(concat default-view-name " 1"))
(t
default-view-name))))
(cond (update default-view-name)
((setq old-view
(cl-find-if
(lambda (x)
(string-match view-name-re (car x)))
ivy-views))
(format "%s %d"
default-view-name
(1+ (string-to-number
(match-string 1 (car old-view))))))
((assoc default-view-name ivy-views)
(concat default-view-name " 1"))
(t
default-view-name))))

(defun ivy--get-view-config ()
"Get `current-window-configuration' for `ivy-views'."
Expand Down Expand Up @@ -4371,7 +4378,7 @@ Use `ivy-pop-view' to delete any item from `ivy-views'."
(if arg
(ivy-read "Update view: " ivy-views)
(ivy-read "Name view: " nil
:initial-input (ivy-default-view-name)))))
:initial-input (ivy-default-view-name :update ivy-default-view-name-update-exist-p)))))
(when view-name
(let ((x (assoc view-name ivy-views)))
(if x
Expand Down