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

Add crux-recentf-find-directory #78

Merged
merged 1 commit into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

* [#65](https://github.com/bbatsov/crux/pull/65): Add a configuration option to move using visual lines in `crux-move-to-mode-line-start`.
* [#72](https://github.com/bbatsov/crux/pull/72): Add `crux-kill-buffer-truename`. Kills path of file visited by current buffer.
* [#78](https://github.com/bbatsov/crux/pull/78): Add `crux-recentf-find-directory`. Open recently visited directory.

### Bugs fixed

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Command | Suggested Keybinding(s)
`crux-smart-open-line` | <kbd>S-RET</kbd> or <kbd>M-o</kbd> | Insert an empty line and indent it properly (as in most IDEs).
`crux-cleanup-buffer-or-region` | <kbd>C-c n</kbd> | Fix indentation in buffer and strip whitespace.
`crux-recentf-find-file` | <kbd>C-c f</kbd> or <kbd>Super-r</kbd> | Open recently visited file.
`crux-recentf-find-directory` | <kbd>C-c F</kbd> | Open recently visited directory.
`crux-view-url` | <kbd>C-c u</kbd> | Open a new buffer containing the contents of URL.
`crux-eval-and-replace` | <kbd>C-c e</kbd> | Eval a bit of Emacs Lisp code and replace it with its result.
`crux-transpose-windows` | <kbd>C-x 4 t</kbd> | Transpose the buffers between two windows.
Expand Down
19 changes: 14 additions & 5 deletions crux.el
Original file line number Diff line number Diff line change
Expand Up @@ -606,17 +606,26 @@ as the current user."
(insert (format-time-string "%c" (current-time))))

;;;###autoload
(defun crux-recentf-find-file ()
"Find a recent file using `completing-read'."
(defun crux-recentf-find-file (&optional filter)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively you can make this some private helper function and have a single command be used for files and directories depending on whether it was used with a prefix argument (e.g. C-u C-c f). I don't have a strong preference either way, though - just something that came to my mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong preference either. Your call 🙂

"Find a recent file using `completing-read'.
When optional argument FILTER is a function, it is used to
transform recent files before completion."
(interactive)
(let ((file (completing-read "Choose recent file: "
(mapcar #'abbreviate-file-name recentf-list)
nil t)))
(let* ((filter (if (functionp filter) filter #'abbreviate-file-name))
(file (completing-read "Choose recent file: "
(delete-dups (mapcar filter recentf-list))
nil t)))
(when file
(find-file file))))

(define-obsolete-function-alias 'crux-recentf-ido-find-file 'crux-recentf-find-file "0.4.0")

;;;###autoload
(defun crux-recentf-find-directory ()
"Find a recent directory using `completing-read'."
(interactive)
(crux-recentf-find-file (lambda (file) (abbreviate-file-name (file-name-directory file)))))

;; modified from https://www.emacswiki.org/emacs/TransposeWindows
;;;###autoload
(defun crux-transpose-windows (arg)
Expand Down