reddit / emacs

"Super Buffer File" and Dragon integration

Argletrough · 2022-11-06 11:08
I just spent ages writing these functions, so I thought I'd share them. This is probably the most complex bit of Lisp I've ever written, so feedback would be appreciated! (defun super-buffer-file (&optional buffer-or-name) "Name of a local file containing buffer `BUFFER-OR-NAME''s contents. Uses `file-local-copy' and `make-temp-file' if necessary to make a file to use. Uses `current-buffer' by default." (interactive) (let* ((buf (get-buffer (or buffer-or-name (current-buffer)))) (name (buffer-name buf))) (if buf (with-current-buffer buf (or (and (buffer-file-name) (or (file-local-copy (buffer-file-name)) (file-local-name (buffer-file-name)))) (let ((tmp-file (make-temp-file (buffer-name)))) (write-file tmp-file) tmp-file))) buffer-or-name))) (defun dragon-buffer (&optional buffer-or-file) "Call dragon on `BUFFER-OR-FILE'. If unspecified, `dired-get-marked-files' is used. If that is unspecified (not a Dired buffer), `current-buffer' is used. Uses `super-buffer-file' to get a file for a non-Dired buffer." (interactive) (set-process-sentinel (eval (append '(start-process "Dragon" (concat "*Dragon: " (buffer-name) "*") "dragon-drag-and-drop") (or (and (null buffer-or-file) (dired-get-marked-files)) (list (super-buffer-file buffer-or-file))))) `(lambda (process signal) (and (memq (process-status process) '(exit signal)) (buffer-live-p (process-buffer process)) (kill-buffer (process-buffer process)))))) (global-set-key (kbd "C-<f1>") 'dragon-buffer)
Argletrough · 2022-11-06 11:11
Also please tell me if there's a built-in function that does the same thing as `super-buffer-file`.
holgerschurig · 2022-11-06 13:58
For that I'd need to understand what this function does. The help text for the function isn't exactly enlightening. What do you want to achieve, why do you want to make a local copy? Is your use-case a remote (via Tramp) buffer? The elisp doesn't seem to indicate this ... I also have no idea what a "super" buffer is supposed to be. A better buffer? Or hierarchically up (e.g.whrn thinking in hierarchies) ??
Argletrough · 2022-11-07 21:09
Yeah, some amount of extra explanation would have helped. I'm using this with a local program ([https://github.com/mwh/dragon](https://github.com/mwh/dragon)) that creates a pop-up GUI window (independent of Emacs) for "drag and drop" functionality. It only works with files on the local system, so the purpose of `super-buffer-file` is to create a local file associated with a buffer if one doesn't already exist, and return the name of that file. The name was just me being too full of myself. :P