Fanael / edit-indirect

Edit regions in separate buffers
99 stars 23 forks source link

How to open in current window? #18

Closed mohkale closed 3 years ago

mohkale commented 3 years ago

I don't like windows popping up all over the place so for some types of popups I like to make them open in the current window.

I tried this but it doesn't seem to work :cry:.

(push (cons (rx bol "*edit-indirect ")
            '(display-buffer-reuse-window
              display-buffer-same-window))
      display-buffer-alist)
Fanael commented 3 years ago

You can set the third argument of edit-indirect-region to nil to create an edit-indirect buffer without displaying it, and switch the current window to that buffer in a custom command:

(defun switch-to-edit-indirect-region (beg end)
  (interactive
   (if (or (use-region-p) (not transient-mark-mode))
       (prog1 (list (region-beginning) (region-end))
         (deactivate-mark))
     (user-error "No region")))
  (switch-to-buffer (edit-indirect-region beg end nil)))
mohkale commented 3 years ago

@Fanael

My bad the format of my display-buffer-alist entry wasn't correct. The second entry is supposed to be a list of functions not a symbol. This works.

(push (cons (rx bol "*edit-indirect ")
        '((display-buffer-reuse-window
            display-buffer-same-window)))
  display-buffer-alist)
mohkale commented 3 years ago

@Fanael

It's also worth pointing out you probably shouldn't do (select-window (display-buffer buffer)). While I actually prefer selecting popup windows this should be configured using display-buffer-alist (eg. setting an action to (body-function . select-window)).

The way some other packages do this is by exposing a defcustom for the action argument passed to the display-buffer function. For example bufler.