help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make new buffer from menu


From: Jean Louis
Subject: Re: Make new buffer from menu
Date: Sun, 4 Dec 2022 15:03:05 +0300
User-agent: Mutt/2.2.9+50 (c79959e) (2022-11-21)

* Heime <heimeborgia@protonmail.com> [2022-12-03 06:59]:
> 
> It would help me a lot if can can make a new buffer that I can set with 
> some major mode, from the menu.
> 
> One cannot make a new buffer without saving it.

I make new buffer with {C-x b name-of-my-new-buffer} and I use this
below to create buffers by using {C-u F5}, I bind it to F5, so by
using prefix, I choose the mode.

For required functions see the package:

GNU Emacs package: rcd-utilities.el :
https://gnu.support/gnu-emacs/packages/rcd-utilities-el.html

;;; RCD TEMPORARY BUFFERS

(defcustom rcd-temp-file-directory "~/tmp/"
  "Temporary directory for other temporary files."
  :group 'rcd
  :type 'string)

(defvar rcd-temp-buffer-name "RCD TEMPORARY BUFFER")
(defvar rcd-temp-buffer-modes '(("adoc-mode" . "adoc")
                                ("emacs-lisp-mode" . "el")
                                ("lisp-mode" . ".lisp")
                                ("markdown-mode" . ".md")
                                ("org-mode" . "org")
                                ("sql-mode" . "sql")
                                ("fundamental-mode" . "txt")
                                ("html-mode" . "html")))

(defun rcd-temp-buffer (&optional prefix name mode)
  "Generate new temporary buffer."
  (interactive "p")
  (let* ((file-name (concat rcd-temp-file-directory 
                            (format-time-string "%Y-%m-%d-%H:%M:%S-")
                            rcd-temp-buffer-name
                            ".txt"))
         (buffer (or name (concat "*" rcd-temp-buffer-name "*"))))
    (switch-to-buffer (generate-new-buffer buffer))
    (setq buffer-file-name file-name)
    (if current-prefix-arg
        (let ((mode (rcd-choose (map-keys rcd-temp-buffer-modes) "Major mode: 
")))
          (funcall (intern mode)))
      (funcall (intern (or mode "fundamental-mode"))))
    buffer-file-name))

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]