all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: R scratch buffer
Date: Thu, 12 Jul 2012 18:15:52 +0200	[thread overview]
Message-ID: <87txxd6jlz.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: f85a87cc-be13-4707-afc3-ff5d5822de44@googlegroups.com

"Benoit G." <benoit.goussen@gmail.com> writes:

> Dear all,
>
> I am trying to make a second scratch buffer which enable automatically the R-mode.
> I copy-paste-modified a code I found on the www but this don't seems to work (the buffer is created but in fundmental mode).
>
> Can you help me solving this issue?
>
> Here is a part of my .emacs file :
>
>    (save-excursion
>       (set-buffer (get-buffer-create "*scratch-R*"))
>       (R-mode)
>       (make-local-variable 'kill-buffer-query-functions)
>       (add-hook 'kill-buffer-query-functions 'kill-scratch-R-buffer))
>
>     (defun kill-scratch-R-buffer ()
>       ;; The next line is just in case someone calls this manually
>       (set-buffer (get-buffer-create "*scratch-R*"))
>       ;; Kill the current (*scratch-R*) buffer
>       (remove-hook 'kill-buffer-query-functions 'kill-scratch-R-buffer)
>       (kill-buffer (current-buffer))
>       ;; Make a brand new *scratch-R* buffer
>       (set-buffer (get-buffer-create "*scratch-R*"))
>       (R-mode)
>       (make-local-variable 'kill-buffer-query-functions)
>       (add-hook 'kill-buffer-query-functions 'kill-scratch-R-buffer)
>       ;; Since we killed it, don't let caller do that.
>       nil)


I'd rather do something like this:

    (defun r-scratch ()
      "Create and/or switch to the *R-scratch* buffer."
      (interactive)
      (switch-to-buffer (get-buffer-create "*R-scratch*"))
      (R-mode)
      (add-hook 'kill-buffer-query-functions 'kill-scratch-R-buffer))


    (defun kill-scratch-R-buffer ()
       "If the current buffer is the *R-scratch* buffer, then  kill it
     and recreate a virgin *R-scratch* buffer."
       (when (eq (get-buffer "*R-scratch*") (current-buffer))
         (kill-buffer (current-buffer))
         (r-scratch))
      nil)
   

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


  reply	other threads:[~2012-07-12 16:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-12 15:48 R scratch buffer Benoit G.
2012-07-12 16:15 ` Pascal J. Bourguignon [this message]
2012-07-13  7:52   ` Benoit G.
2012-07-13  7:56   ` Benoit G.
2012-07-13  8:31     ` Pascal J. Bourguignon
2012-07-13  9:22       ` Benoit G.
2012-07-13 10:12         ` Pascal J. Bourguignon
2012-07-13 12:18           ` Benoit G.
2012-07-13 12:32             ` Pascal J. Bourguignon
2012-07-13 12:46               ` Benoit G.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87txxd6jlz.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.