reddit / emacs

Help wanted. Emacs doesnt really deletes "special" windows when pressing Q

konrad1977 · 2022-02-26 08:09
Hi, some buffers can be deleted/hiddden using "q", like help buffers etc (they probably have a name). xwidget seems to disapear (but its only hidden) and when its hidden it always shows another buffer instead. How can I configure this to actually quit the buffer and delete the window? This is my function for splitting and showing the browser on the right. (defun mk/browser-split-window (url &optional new-window) "Create a new browser window to the right of the current one." (interactive) (let* ((ignore-window-parameters t) (dedicated-p (window-dedicated-p))) (delete-other-windows) (split-window-horizontally) (other-window 1) (xwidget-webkit-browse-url url))) [Looks nice - now lets close it using \\"q\\"](https://preview.redd.it/ozqnujlby4k81.png?width=3576&format=png&auto=webp&s=0d8aaf72345c305f0c2d9087c5cb368a3aa827d4) [Hmm not really what I wanted.](https://preview.redd.it/ns6jxjlby4k81.png?width=3576&format=png&auto=webp&s=3ff89f57af765587591d43eea758c39edac3488e) My complete config can be found here: [https://github.com/konrad1977/emacs](https://github.com/konrad1977/emacs) **And as a bonus I have another question:** How do I setup emacs to always set focus to `(other-window 1)` when a new window is created? Thanks!
karthink · 2022-02-26 08:25
What is `q` bound to in the xwidget?
konrad1977 · 2022-02-26 09:40
quit-window
Vince_Vice · 2022-02-26 10:31
I don't know a lot. But > (they probably have a name). The ones enclosed in "*", I believe, are called "special buffers" Also, maybe a rules based approach can fit your needs like, i.e., [shackle](https://depp.brause.cc/shackle/) provides. I haven't used it for a long time, maybe there are better packages out there now but IIRC it allows you to define what should happpen to buffers grouped by regex and their respective windows on creation or deletion. On a side note: Your emacsen looks stylish!
Lazy-Snail · 2022-02-26 10:44
If you use `quit-window` and want it to delete the window, one of the following requirements must be met : - The window is strongly dedicated (set-window-dedicated-p (current-window) t) - The window *does not* have a window history. This can happen when invoking the right display-buffer functions. You should consider to cook your own`display-buffer-alist` instead of cooking your own functions to display buffer.
konrad1977 · 2022-02-26 13:33
Ok, any good examples for this? Some I want to identify by name and others by mode (I guess)?
konrad1977 · 2022-02-26 13:53
I did something like this ​ (use-package window :ensure nil :custom (display-buffer-alist '( ("\Faces\|[Hh]elp\" (display-buffer-in-side-window) (window-width . 0.33) (side . right) (slot . 1)) ("\simulator logs\|Flycheck errors\|Async Shell Command\|[Cc]olors\" (display-buffer-in-side-window) (window-height . 0.25) (side . bottom) (slot . 0)) ))) How do I make them selected after they are opened? And how can I check for modes instead of name?
Lazy-Snail · 2022-02-26 14:21
1. (body-function . (lambda (window) (select-window window))) 2. ;; use a predicate function : (add-to-list 'display-buffer-alist '(scratch-p (display-buffer-in-side-window) (body-function . (lambda (window) (select-window window))) (side . bottom) (slot . 1) (window-height . 0.3))) (defun scratch-p (buffer _alist) (equal buffer "*scratch*")) (display-buffer (get-buffer-create "*scratch*"))
konrad1977 · 2022-02-26 14:35
> (body-function . (lambda (window) (select-window window))) Thank you very much. This helped a lot.
fragglestickcar0 · 2022-02-26 15:41
(- (line-end-position) (line-beginning-position))
Visual_Bumblebee_555 · 2022-02-26 15:59
I prefer to kill the window with "q" key binding for specific major modes instead of the default `quit-window`, so I've written this in my init file. Maybe something equivalent is available with xwidget? ``` (defun my/quit-window-force () "Quit the window completely instead of burying it when in doc-view and image modes." (interactive) (quit-window t)) (use-package doc-view-mode :bind (:map doc-view-mode-map ("q" . my/quit-window-force))) (use-package image-mode :bind (:map image-mode-map ("q" . my/quit-window-force))) ``` I find this to be much easier than `C-x 4 0`.
00-11 · 2022-02-26 17:09
I use this (from [`misc-cmds.el`](https://www.emacswiki.org/emacs/download/misc-cmds.el): (defun quit-window-delete (&optional kill window) "Quit WINDOW, deleting it, and bury its buffer. WINDOW must be a live window and defaults to the selected one. With prefix argument KILL non-nil, kill the buffer instead of burying it. This is similar to the version of `quit-window' that Emacs had before the introduction of `quit-restore-window'. It ignores the information stored in WINDOW's `quit-restore' window parameter. It deletes the WINDOW more often, rather than switching to another buffer in it. If WINDOW is alone in its frame then the frame is deleted or iconified, according to option `frame-auto-hide-function'." (interactive "P") (set-window-parameter window 'quit-restore `(frame frame nil ,(current-buffer))) (quit-restore-window window (if kill 'kill 'bury))) And I do this, to bind `q` etc. to the command: (define-key global-map [remap quit-window] 'quit-window-delete)
konrad1977 · 2022-02-26 18:21
Thank you Mostly thanks to the theme I ported. Its called kanagawa. It can be found here: [https://github.com/konrad1977/emacs/tree/main/themes](https://github.com/konrad1977/emacs/tree/main/themes)
konrad1977 · 2022-02-26 18:24
Hmm that clever, I wonder if I can add :bind some how to the xwidget-webkit. Its emacs after all, but its added a compiler flag.
konrad1977 · 2022-02-26 18:25
This magically worked, but I changed the quit-window-delete to evil-quit. I guess its because xwidget-webkit runs in its own spawned process?
karthink · 2022-02-26 20:09
I would have thought that `(lambda (win) (select-window win))` is identical to `#'select-window` (minus an optional second argument to `select-window` that's not used). But setting (body-function . #'select-window) only selects the buffer when it is created, and not on subsequent calls to `display-buffer`, whereas the equivalent lambda works consistently. Any idea why? EDIT: `(body-function . select-window)` works fine. It looks like the spec argument is already quoted, so `#'select-window` or `'select-window)` is wrong. So `(body-function . (lambda () ....))` can be replaced with `(body-function . select-window)`.
Lazy-Snail · 2022-02-26 23:21
>Any idea why? Because at the end of this call there is something like : `(funcall (cdr (assq 'body-function alist)) window)` So yes, it already gets the symbol, and does not need extra quoting... Anyway you are right, `(body-function . select-window)` is quicker in this case.
crawsphi · 2022-02-27 19:16
`display-buffer-alist` doesn't have a setter defined, so you might want to use `add-to-list` instead of `:custom` in case there are additions being made to it elsewhere.