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

Delete file or kill buffer DWIM [Feature request] #164

Closed
kaushalmodi opened this Issue Jun 30, 2015 · 13 comments

Comments

Projects
None yet
4 participants
@kaushalmodi
Contributor

kaushalmodi commented Jun 30, 2015

I have switched to using counsel and ivy instead of ido and this is one of the features I miss from ido:

  1. When doing C-x C-f, if the selection is on a file name that is not open in one of the buffers, C-k will delete (or trash, depending on delete-by-moving-to-trash) that file name.
  2. When switching buffers, C-k will kill the selected buffer if open. If the buffer is already closed (virtual buffer) and if that buffer was associated to a file name, that file will be deleted (or trashed).

It will be nice to have these functionalities in counsel-find-file and ivy-switch-buffer.

Currently, I need to switch to that file/buffer and then delete/kill it.

abo-abo added a commit that referenced this issue Jun 30, 2015

Add a custom keymap for ivy-switch-buffer
* ivy.el (ivy-switch-buffer-map): New defvar.

Re #164

abo-abo added a commit that referenced this issue Jun 30, 2015

Add a custom keymap for counsel-find-file
* counsel.el (counsel-find-file-map): New defvar.

Re #164
@abo-abo

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Jun 30, 2015

Owner

You could add something like this to your config:

(define-key
    ivy-switch-buffer-map
    (kbd "C-k")
  (lambda ()
    (interactive)
    (ivy-set-action 'kill-buffer)
    (ivy-done)))

I'm currently working on multiple actions for a single command. Similar to counsel-describe-variable, except the key bindings aren't hard coded. Maybe that could solve your problem as well:

  1. Call ivy-switch-buffer
  2. C-o to open up options.
  3. w / s to select the buffer kill action, instead of the default switch-to-buffer action.
  4. Use C-M-n to kill a bunch of buffers, while skipping some with C-n.
Owner

abo-abo commented Jun 30, 2015

You could add something like this to your config:

(define-key
    ivy-switch-buffer-map
    (kbd "C-k")
  (lambda ()
    (interactive)
    (ivy-set-action 'kill-buffer)
    (ivy-done)))

I'm currently working on multiple actions for a single command. Similar to counsel-describe-variable, except the key bindings aren't hard coded. Maybe that could solve your problem as well:

  1. Call ivy-switch-buffer
  2. C-o to open up options.
  3. w / s to select the buffer kill action, instead of the default switch-to-buffer action.
  4. Use C-M-n to kill a bunch of buffers, while skipping some with C-n.

abo-abo added a commit that referenced this issue Jun 30, 2015

Fixup the last two commits
* counsel.el (counsel-find-file): Update.

* ivy.el (ivy--buffer-list): Update.

Re #164

abo-abo added a commit that referenced this issue Jun 30, 2015

ivy.el (ivy-switch-buffer): Add a multi-action interface
While in "C-o":

- Use "s" to make "C-m", "C-j", "C-M-n" and "C-M-p" kill
- Use "w" to switch back to normal.

Re #164
@kaushalmodi

This comment has been minimized.

Show comment
Hide comment
@kaushalmodi

kaushalmodi Jul 2, 2015

Contributor

Works great with ivy-switch-buffer. Would like to implement 'delete file' function in counsel-find-file in a similar fashion.

btw, why have the ivy- prefix for ivy-switch-buffer and counsel- for almost everything else?

Contributor

kaushalmodi commented Jul 2, 2015

Works great with ivy-switch-buffer. Would like to implement 'delete file' function in counsel-find-file in a similar fashion.

btw, why have the ivy- prefix for ivy-switch-buffer and counsel- for almost everything else?

@kaushalmodi

This comment has been minimized.

Show comment
Hide comment
@kaushalmodi

kaushalmodi Jul 2, 2015

Contributor
    (defun counsel-find-file ()
      "Forward to `find-file'."
      (interactive)
      (ivy-read "Find file: " 'read-file-name-internal
                :matcher #'counsel--find-file-matcher
                :action (cons
                         1
                         `(("default"
                            (lambda (x)
                              (find-file
                               (expand-file-name x ivy--directory))))
                           (,(propertize "delete"
                                         'face 'font-lock-warning-face)
                            (lambda (x)
                              (delete-file
                               (expand-file-name x ivy--directory))))))
                :preselect (when counsel-find-file-at-point
                             (require 'ffap)
                             (ffap-guesser))
                :require-match 'confirm-after-completion
                :history 'file-name-history
                :keymap counsel-find-file-map))
Contributor

kaushalmodi commented Jul 2, 2015

    (defun counsel-find-file ()
      "Forward to `find-file'."
      (interactive)
      (ivy-read "Find file: " 'read-file-name-internal
                :matcher #'counsel--find-file-matcher
                :action (cons
                         1
                         `(("default"
                            (lambda (x)
                              (find-file
                               (expand-file-name x ivy--directory))))
                           (,(propertize "delete"
                                         'face 'font-lock-warning-face)
                            (lambda (x)
                              (delete-file
                               (expand-file-name x ivy--directory))))))
                :preselect (when counsel-find-file-at-point
                             (require 'ffap)
                             (ffap-guesser))
                :require-match 'confirm-after-completion
                :history 'file-name-history
                :keymap counsel-find-file-map))

@kaushalmodi kaushalmodi closed this Jul 2, 2015

@abo-abo

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Jul 3, 2015

Owner

btw, why have the ivy- prefix for ivy-switch-buffer and counsel- for almost everything else?

Because most of ivy-switch-buffer is in ivy.el, and it's part of ivy-mode via:

(define-key map [remap switch-to-buffer] 'ivy-switch-buffer)

I tried remapping counsel-find-file, it didn't work for some reason.

Owner

abo-abo commented Jul 3, 2015

btw, why have the ivy- prefix for ivy-switch-buffer and counsel- for almost everything else?

Because most of ivy-switch-buffer is in ivy.el, and it's part of ivy-mode via:

(define-key map [remap switch-to-buffer] 'ivy-switch-buffer)

I tried remapping counsel-find-file, it didn't work for some reason.

@abo-abo

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Jul 3, 2015

Owner

Would like to implement 'delete file' function in counsel-find-file in a similar fashion.

I'm afraid of deleting files by accident: by mashing sc you can delete a file by accident. But I don't want to make you redefine counsel-find-file if you choose to have that functionality. Maybe I could add ivy-extra-actions-alist similar to ivy-initial-inputs-alist. What do you think?

Owner

abo-abo commented Jul 3, 2015

Would like to implement 'delete file' function in counsel-find-file in a similar fashion.

I'm afraid of deleting files by accident: by mashing sc you can delete a file by accident. But I don't want to make you redefine counsel-find-file if you choose to have that functionality. Maybe I could add ivy-extra-actions-alist similar to ivy-initial-inputs-alist. What do you think?

@kaushalmodi

This comment has been minimized.

Show comment
Hide comment
@kaushalmodi

kaushalmodi Jul 3, 2015

Contributor

Maybe I could add ivy-extra-actions-alist similar to ivy-initial-inputs-alist.

I am fine redefining that function. But adding that variable would also mean easy customizability of any function using ivy; so go for it. Thanks! :)

I also feared of accidental deletion and so I gave font-lock-warning-face to delete option. I can even go further and wrap the delete-file in y-or-n-p.

Contributor

kaushalmodi commented Jul 3, 2015

Maybe I could add ivy-extra-actions-alist similar to ivy-initial-inputs-alist.

I am fine redefining that function. But adding that variable would also mean easy customizability of any function using ivy; so go for it. Thanks! :)

I also feared of accidental deletion and so I gave font-lock-warning-face to delete option. I can even go further and wrap the delete-file in y-or-n-p.

abo-abo added a commit that referenced this issue Jul 6, 2015

Add a new interface to customize additional exit points
* ivy.el (ivy--actions-list): New defvar. Store the exit points per
  command.
(ivy-set-actions): New defun. Use this to set the extra exit points for
each command.
(ivy-read): Account for `ivy--actions-list'.
(ivy-switch-buffer): Set extra action to kill the buffer. Update the
call to `ivy-read'.

* counsel.el (counsel-locate): Use the single action in the function and
  customize the rest via `ivy-set-actions'.

Re #164
@abo-abo

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Jul 6, 2015

Owner

Added the new interface. Give it a try for your file-deleting application.

Owner

abo-abo commented Jul 6, 2015

Added the new interface. Give it a try for your file-deleting application.

@kaushalmodi

This comment has been minimized.

Show comment
Hide comment
@kaushalmodi

kaushalmodi Jul 6, 2015

Contributor

Works great! Thank you.

(ivy-set-actions
 'counsel-find-file
 `((,(propertize "delete" 'face 'font-lock-warning-face)
    (lambda (x) (delete-file (expand-file-name x ivy--directory))))))
Contributor

kaushalmodi commented Jul 6, 2015

Works great! Thank you.

(ivy-set-actions
 'counsel-find-file
 `((,(propertize "delete" 'face 'font-lock-warning-face)
    (lambda (x) (delete-file (expand-file-name x ivy--directory))))))
@JohnLunzer

This comment has been minimized.

Show comment
Hide comment
@JohnLunzer

JohnLunzer Jun 15, 2018

I have a question regarding the switch-buffer kill, (ivy-done) closes the ivy minibuffer which is not desirable for me. I changed it to (ivy-done) to (ivy-call) and it performs the action but the ivy minibuffer doesn't update as I would have expected.

What would I have to add to kill a buffer, keep the ivy minibuffer open, and update the ivy-minibuffer to get rid of the killed buffer?

I'm also using ivy-rich, just in case you can't reproduce.

JohnLunzer commented Jun 15, 2018

I have a question regarding the switch-buffer kill, (ivy-done) closes the ivy minibuffer which is not desirable for me. I changed it to (ivy-done) to (ivy-call) and it performs the action but the ivy minibuffer doesn't update as I would have expected.

What would I have to add to kill a buffer, keep the ivy minibuffer open, and update the ivy-minibuffer to get rid of the killed buffer?

I'm also using ivy-rich, just in case you can't reproduce.

@abo-abo

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Jun 15, 2018

Owner

@JohnLunzer I think you're looking for C-c C-k.

Owner

abo-abo commented Jun 15, 2018

@JohnLunzer I think you're looking for C-c C-k.

@JohnLunzer

This comment has been minimized.

Show comment
Hide comment
@JohnLunzer

JohnLunzer Jun 15, 2018

You know... you just have the answer for everything don't you ;) That's great. With that command and Ivy-rich I feel like I can abandon bs-show

Out of curiosity, so I don't ask stupid questions in the future, what is the prescribed method for showing ivy-x-map keybindings while in an ivy minibuffer?

JohnLunzer commented Jun 15, 2018

You know... you just have the answer for everything don't you ;) That's great. With that command and Ivy-rich I feel like I can abandon bs-show

Out of curiosity, so I don't ask stupid questions in the future, what is the prescribed method for showing ivy-x-map keybindings while in an ivy minibuffer?

@abo-abo

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Jun 15, 2018

Owner

Out of curiosity, so I don't ask stupid questions in the future, what is the prescribed method for showing ivy-x-map keybindings while in an ivy minibuffer?

Usually, describe-mode should work. But it doesn't show you the C-c C-k binding in this case. We'll need to improve the discoverability in the future.

Owner

abo-abo commented Jun 15, 2018

Out of curiosity, so I don't ask stupid questions in the future, what is the prescribed method for showing ivy-x-map keybindings while in an ivy minibuffer?

Usually, describe-mode should work. But it doesn't show you the C-c C-k binding in this case. We'll need to improve the discoverability in the future.

@basil-conto

This comment has been minimized.

Show comment
Hide comment
@basil-conto

basil-conto Jun 15, 2018

Contributor

Usually, describe-mode should work. But it doesn't show you the C-cC-k binding in this case. We'll need to improve the discoverability in the future.

What about C-hb, AKA describe-bindings or, with counsel-mode enabled, counsel-descbinds?

Contributor

basil-conto commented Jun 15, 2018

Usually, describe-mode should work. But it doesn't show you the C-cC-k binding in this case. We'll need to improve the discoverability in the future.

What about C-hb, AKA describe-bindings or, with counsel-mode enabled, counsel-descbinds?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment