Skip to content

Commit

Permalink
Switch between counsel-file-jump/counsel-find-file
Browse files Browse the repository at this point in the history
* counsel.el (counsel-file-jump-from-find): Specify
default-directory when switching to counsel-file-jump.
(counsel-find-file): Accept new optional argument specifying
default-directory.
(counsel-find-file-from-jump): New command.
(counsel-file-jump-map): New keymap.
(counsel-file-jump): Use it.

Closes #2756.
  • Loading branch information
ngharrison authored and basil-conto committed Jan 9, 2021
1 parent 764b978 commit 8f2abd3
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions counsel.el
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,7 @@ currently checked out."
"Switch to `counsel-file-jump' from `counsel-find-file'."
(interactive)
(ivy-quit-and-run
(counsel-file-jump ivy-text)))
(counsel-file-jump ivy-text (ivy-state-directory ivy-last))))

(when (executable-find "git")
(add-to-list 'ivy-ffap-url-functions 'counsel-github-url-p)
Expand Down Expand Up @@ -2026,14 +2026,14 @@ The preselect behavior can be customized via user options
:caller caller)))

;;;###autoload
(defun counsel-find-file (&optional initial-input)
(defun counsel-find-file (&optional initial-input initial-directory)
"Forward to `find-file'.
When INITIAL-INPUT is non-nil, use it in the minibuffer during completion."
(interactive)
(counsel--find-file-1
"Find file: " initial-input
#'counsel-find-file-action
'counsel-find-file))
(let ((default-directory (or initial-directory default-directory)))
(counsel--find-file-1 "Find file: " initial-input
#'counsel-find-file-action
'counsel-find-file)))

(ivy-configure 'counsel-find-file
:parent 'read-file-name-internal
Expand Down Expand Up @@ -2841,6 +2841,18 @@ FZF-PROMPT, if non-nil, is passed as `ivy-read' prompt argument."
:type '(repeat string))

;;** `counsel-file-jump'
(defvar counsel-file-jump-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "`") #'counsel-find-file-from-jump)
map)
"Key bindings to be used when in a file-jump minibuffer.")

(defun counsel-find-file-from-jump ()
"Switch to `counsel-find-file' from `counsel-file-jump'."
(interactive)
(ivy-quit-and-run
(counsel-find-file ivy-text (ivy-state-directory ivy-last))))

;;;###autoload
(defun counsel-file-jump (&optional initial-input initial-directory)
"Jump to a file below the current directory.
Expand All @@ -2861,6 +2873,7 @@ INITIAL-DIRECTORY, if non-nil, is used as the root directory for search."
:preselect (counsel--preselect-file)
:require-match 'confirm-after-completion
:history 'file-name-history
:keymap counsel-file-jump-map
:caller 'counsel-file-jump)))

(ivy-set-actions
Expand Down

0 comments on commit 8f2abd3

Please sign in to comment.