unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Christopher Dimech <dimech@gmx.com>
To: Christopher Dimech <dimech@gmx.com>
Cc: Jean Louis <bugs@gnu.support>,
	carlmarcos@tutanota.com, Help Gnu Emacs <help-gnu-emacs@gnu.org>
Subject: Re: Adding major-mode selection to new buffer
Date: Wed, 29 Jun 2022 12:47:21 +0200	[thread overview]
Message-ID: <trinity-badfd900-dfe9-4085-9612-e55441d7145c-1656499641052@3c-app-mailcom-bs02> (raw)
In-Reply-To: <trinity-b9f23afb-a519-470c-bc3a-6da4b8db25e5-1656454841173@3c-app-mailcom-bs02>




> Sent: Wednesday, June 29, 2022 at 10:20 AM
> From: "Christopher Dimech" <dimech@gmx.com>
> To: "Jean Louis" <bugs@gnu.support>
> Cc: carlmarcos@tutanota.com, "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> Subject: Re: Adding major-mode selection to new buffer
>
> > Sent: Tuesday, June 28, 2022 at 10:21 PM
> > From: "Jean Louis" <bugs@gnu.support>
> > To: carlmarcos@tutanota.com
> > Cc: "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> > Subject: Re: Adding major-mode selection to new buffer
> >
> > * carlmarcos--- via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2022-06-28 01:51]:
> > > With the following function I can make a new buffer with a name.  Would also 
> > > like to set the major-mode from the minibuffer.
> > > 
> > I am using this below to open up new temporary buffers with name
> > assigned or with automatic name, and with the possibility to choose
> > the major mode.
> 
> Have noticed that the number 1 is inserted when calling `rcd-temp-buffer'.
> This makes a problem when one wants to insert the name when saving

This is because you are using (interactive "p")

> 
>           (file-name
>              (if name
>                  (concat rcd-temp-file-directory
>                          (format-time-string "%Y-%m-%d-T%H:%M:%S--")
>                           rcd-temp-buffer-name "-" name ".org")
>                (concat rcd-temp-file-directory
>                        (format-time-string "%Y-%m-%d-T%H:%M:%S--")
>                        rcd-temp-buffer-name ".org"))) )
> 
> 
>  
> > {C-u M-x rcd-temp-buffer RET} will ask for mode to be used
> > 
> > {M-x rcd-temp-buffer RET}} will open new temporary buffer
> > 
> > {M-x rcd-temp-buffer RET}} will open new temporary buffer
> > 
> > {M-x rcd-temp-buffer-ask-name RET} will ask for buffer name
> > 
> > {C-u M-x rcd-temp-buffer-ask-name RET} will ask for buffer name and
> > for the mode
> > 
> > Code:
> > 
> > (defvar rcd-temp-buffer-name "RCD TEMPORARY BUFFER")
> > 
> > (defvar rcd-temp-file-directory "~/tmp/")
> > 
> > (defvar rcd-temp-buffer-mode-history nil)
> > 
> > (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 name mode)
> >   "Generate new temporary buffer."
> >   (interactive "p")
> >   (let* ((format (concat "*" rcd-temp-buffer-name "%s%s*"))
> > 	 (buffer (if name (format format ": " name) (format format "" "")))
> > 	 (file-name (concat rcd-temp-file-directory (format-time-string "%Y-%m-%d-%H:%M:%S.txt"))))
> >     (switch-to-buffer (generate-new-buffer buffer))
> >     (setq buffer-file-name file-name)
> >     (if current-prefix-arg
> > 	(let* ((mode (completing-read
> > 		      "Mode: "
> > 		      (map-keys rcd-temp-buffer-modes) nil t nil
> > 		      'rcd-temp-buffer-mode-history)))
> > 	  (funcall (intern mode)))
> >       (funcall (intern (or mode "fundamental-mode"))))
> >     buffer-file-name))
> > 
> > (defun rcd-temp-buffer-ask-name ()
> >   "Generate new temporary buffer by asking for buffer name."
> >   (interactive)
> >   (rcd-temp-buffer
> >    (read-from-minibuffer "Buffer name: ")))
> > 
> > (global-set-key (kbd "<f5>") #'rcd-temp-buffer)
> > 
> > -- 
> > Jean
> > 
> > Take action in Free Software Foundation campaigns:
> > https://www.fsf.org/campaigns
> > 
> > In support of Richard M. Stallman
> > https://stallmansupport.org/
> > 
> >
> 
>



  reply	other threads:[~2022-06-29 10:47 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-27 22:46 Adding major-mode selection to new buffer carlmarcos--- via Users list for the GNU Emacs text editor
2022-06-27 23:06 ` Emanuel Berg
2022-06-27 23:09   ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-06-27 23:13     ` Emanuel Berg
2022-06-27 23:24       ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-06-27 23:29         ` Emanuel Berg
2022-06-28  0:03           ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-06-28  0:19             ` Emanuel Berg
2022-06-28  0:28 ` Chris Van Dusen
2022-06-28 10:21 ` Jean Louis
2022-06-28 22:05   ` Christopher Dimech
2022-06-29 10:57     ` Jean Louis
     [not found]     ` <YrwwJ0/FaRxg2Ryn@protected.localdomain-N5j6REm----2>
2022-06-29 16:05       ` carlmarcos--- via Users list for the GNU Emacs text editor
     [not found]       ` <N5jJkLB--3-2@tutanota.com-N5kDENb----2>
2022-06-29 16:42         ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-06-30 13:06           ` Jean Louis
2022-06-30 14:37             ` [External] : " Drew Adams
2022-06-30 15:07               ` Jean Louis
2022-06-28 22:20   ` Christopher Dimech
2022-06-29 10:47     ` Christopher Dimech [this message]
     [not found] ` <YrrWHhpK7uiKKVb1@protected.localdomain-N5dqNXf--J-2>
2022-06-28 12:40   ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-06-28 18:22     ` Jean Louis

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=trinity-badfd900-dfe9-4085-9612-e55441d7145c-1656499641052@3c-app-mailcom-bs02 \
    --to=dimech@gmx.com \
    --cc=bugs@gnu.support \
    --cc=carlmarcos@tutanota.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).