The attached patch associates *slime-scratch* with a file if you name one as "slime-scratch-file". I've been running slime with this a while, and rather like it.
Something like this was talked about a while ago, and dropped because of what looked like an ideologinal objection to scratch-buffers in my mind.
Is the consensus still against this?
Cheers,
-- Nikodemus
Index: slime.el =================================================================== RCS file: /project/slime/cvsroot/slime/slime.el,v retrieving revision 1.784 diff -u -r1.784 slime.el --- slime.el 16 Apr 2007 14:42:33 -0000 1.784 +++ slime.el 27 Apr 2007 13:26:17 -0000 @@ -4570,10 +4570,15 @@ (set-keymap-parent map lisp-mode-map) map))
+(defvar slime-scratch-file nil) + (defun slime-scratch-buffer () "Return the scratch buffer, create it if necessary." (or (get-buffer "*slime-scratch*") - (with-current-buffer (get-buffer-create "*slime-scratch*") + (with-current-buffer (if (not slime-scratch-file) + (get-buffer-create "*slime-scratch*") + (find-file slime-scratch-file)) + (rename-buffer "*slime-scratch*") (lisp-mode) (use-local-map slime-scratch-mode-map) (slime-mode t)
* Nikodemus Siivola 4631FB2D.8030208@random-state.net : | The attached patch associates *slime-scratch* with a file | if you name one as "slime-scratch-file". I've been running | slime with this a while, and rather like it. | | Something like this was talked about a while ago, and dropped | because of what looked like an ideologinal objection to | scratch-buffers in my mind. | | Is the consensus still against this?
Personally half the time i don't want a peristent scratch buffer, and half the time, I do, in which case I would bind slime-scratch to: (find-file "/tmp/*slime-scratch*") (slime-switch-to-scratch-buffer)
The only cost of this patch seems to be an extra variable, which I don't mind. On a related note, I've often wondered how, after a file has been associated with the buffer, would one "detach a file from the buffer", without destroying the buffer? -- Madhu
I could be missing something obvious but what is the advantage of the proposed patch as opposed to just use standard commands such as `write-file' or `append-to-file' to save contents of the scratch buffer?
------------------------+----------------------------------------------------- Christian Lynbech | christian #@ defun #. dk ------------------------+----------------------------------------------------- Hit the philistines three times over the head with the Elisp reference manual. - petonic@hal.com (Michael A. Petonic)
Christian Lynbech wrote:
I could be missing something obvious but what is the advantage of the proposed patch as opposed to just use standard commands such as `write-file' or `append-to-file' to save contents of the scratch buffer?
Saving/loading/appending isn't automatic. You need to bother with it. Having a persistent buffer is like having a piece of paper next to your computer: throwing it away is easy, but it isn't going to just disappear on it's own.
Additionally, write-file renames the buffer, so next slime-scratch takes you to another buffer, unless you rename the buffer manually after saving it.
Cheers,
-- Nikodemus
Wouldn't it be better to take a more generic approach and supply a hook? I.e., modify the code to read
(defun slime-scratch-buffer () "Return the scratch buffer, create it if necessary." (or (get-buffer "*slime-scratch*") (with-current-buffer (get-buffer-create "*slime-scratch*") (lisp-mode) (use-local-map slime-scratch-mode-map) (slime-mode t) (run-hooks 'slime-scratch-mode-hook) ; <-- new addition (current-buffer))))
Then the user could just say something like
(defun set-slime-scratch-file-name () (when (and (boundp 'slime-scratch-file) slime-scratch-file) (setf buffer-file-name slime-scratch-file))) (add-hook 'slime-scratch-mode-hook 'set-slime-scratch-file-name)
And if that proposal does not meet with approval, you can always add the hook yourself:
(defun maybe-run-slime-scratch-mode-hook () (when (string= (buffer-name) "*slime-scratch*") (run-hooks 'slime-scratch-mode-hook))) (add-hook 'slime-mode-hook 'maybe-run-slime-scratch-mode-hook t)
- Harald
On Fri, Apr 27, 2007 at 4:31 PM, Nikodemus Siivola nikodemus@random-state.net wrote:
The attached patch associates *slime-scratch* with a file if you name one as "slime-scratch-file". I've been running slime with this a while, and rather like it.
Taking "better late then never" as my cue I finally committed this.
Cheers,
-- Nikodemus