Printing From ibuffer

Ever since I remapped Caps Lock to Control I occasionally type 【Shift+X】 instead of 【Ctrl+X】 or vice-versa. Usually this doesn't make much difference but when I'm in an ibuffer list it invariably causes havoc. The problem normally happens like this: I'm in ibuffer and want to move the cursor up to a different line. Instead of typing 【Ctrl+p】 I type 【Shift+p】. Unfortunately, 【P】 prints the buffer.

Usually I hit 【P】 two or three times before I realize what I've done and end up printing the buffer multiple times (and, of course, it's always a large buffer). I finally got sick of this and added

(defadvice ibuffer-do-print (before print-buffer-query activate)
   (unless (y-or-n-p "Print buffer? ")
     (error "Cancelled")))

to my init.el file. Now when I type 【P】 instead of【Ctrl+p】 Emacs asks me if I really want to print the buffer. Another example of Emacs allowing me to have it my way. The only question is why I waited so long to fix this.

This entry was posted in General and tagged . Bookmark the permalink.
  • Mark

    Nice work -- plai n 'n' and 'p' will also work to navigate in ibuffer though :) (and friends like dired etc)

    • jcs

      I know about n and p but prefer the long forms for muscle memory reasons.

  • Phil

    I've never done that before, but I've immediately grabbed your code as a sensible preventative measure. The idea of sending a whole mass of marked buffers to the printer by accident is fairly unpleasant.

    I see that `define-ibuffer-op' takes a keyword arg `dangerous' which indicates that the user should be prompted, but `(define-ibuffer-op print ...)' doesn't use it.

    • jcs

      The idea of sending a whole mass of marked buffers to the printer by accident is fairly unpleasant.

      Yup. The last time I did it, I managed to print my years-long org-mode todo list 3 times. I had to stand at the printer canceling jobs and still printed a huge number of pages.

      I see that `define-ibuffer-op’ takes a keyword arg `dangerous’ which indicates that the user should be prompted, but `(define-ibuffer-op print …)’ doesn’t use it.

      I know. That's infuriating. At first I thought I could just use that to solve the problem but as you say, define-ibuffer-op-print doesn't use it. Even more infuriating is that eventually print-buffer gets called, which does query the user but only when called interactively. In any event, I've got it fixed now.