all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Adding major-mode selection to new buffer
@ 2022-06-27 22:46 carlmarcos--- via Users list for the GNU Emacs text editor
  2022-06-27 23:06 ` Emanuel Berg
                   ` (3 more replies)
  0 siblings, 4 replies; 21+ messages in thread
From: carlmarcos--- via Users list for the GNU Emacs text editor @ 2022-06-27 22:46 UTC (permalink / raw)
  To: Help Gnu Emacs

With the following function I can make a new buffer with a name.  Would also 
like to set the major-mode from the minibuffer.

Perhaps using `completing-read` 

(cseq '("sh-mode" "emacs-lisp-mode" "org-mode" "f90-mode" "c-mode" ))
(csel  (completing-read "Major Mode: " cseq nil t "org-mode"))

How can I introduce the above functionality in the `workbench' function?

(defun workbench (&optional name)
  "Make new buffer with unique name based on NAME."
  (interactive "s Buffer Name: ")
  (switch-to-buffer
   (generate-new-buffer
    (if (string-blank-p name) "wb" name))))


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Adding major-mode selection to new buffer
  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-28  0:28 ` Chris Van Dusen
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 21+ messages in thread
From: Emanuel Berg @ 2022-06-27 23:06 UTC (permalink / raw)
  To: help-gnu-emacs

carlmarcos--- via Users list for the GNU Emacs text editor wrote:

> Would also like to set the major-mode from the minibuffer.

It is better to set that automatically from the file extension
or the hashbang line.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Adding major-mode selection to new buffer
  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
  0 siblings, 1 reply; 21+ messages in thread
From: carlmarcos--- via Users list for the GNU Emacs text editor @ 2022-06-27 23:09 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs

Jun 27, 2022, 23:06 by incal@dataswamp.org:

> carlmarcos--- via Users list for the GNU Emacs text editor wrote:
>
>> Would also like to set the major-mode from the minibuffer.
>>
>
> It is better to set that automatically from the file extension
> or the hashbang line.
>
They are supposed to be scratch buffers that are not saved, and thus
no extension exists.  This keeps them from being confused with files
the user is working on.
 

> -- 
> underground experts united
> https://dataswamp.org/~incal
>



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Adding major-mode selection to new buffer
  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
  0 siblings, 1 reply; 21+ messages in thread
From: Emanuel Berg @ 2022-06-27 23:13 UTC (permalink / raw)
  To: help-gnu-emacs

carlmarcos--- via Users list for the GNU Emacs text editor wrote:

>> It is better to set that automatically from the file
>> extension or the hashbang line.
>>
> They are supposed to be scratch buffers that are not saved,
> and thus no extension exists.

?

> This keeps them from being confused with files the user is
> working on.

?

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Adding major-mode selection to new buffer
  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
  0 siblings, 1 reply; 21+ messages in thread
From: carlmarcos--- via Users list for the GNU Emacs text editor @ 2022-06-27 23:24 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs



Jun 27, 2022, 23:13 by incal@dataswamp.org:

> carlmarcos--- via Users list for the GNU Emacs text editor wrote:
>
>>> It is better to set that automatically from the file
>>> extension or the hashbang line.
>>>
>> They are supposed to be scratch buffers that are not saved,
>> and thus no extension exists.
>>
They are made as named scratch buffers, with a major-mode setup.
The save button is not available but one can use `C-x C-w'.

>
>
>> This keeps them from being confused with files the user is
>> working on.
>>
>
> ?
>
> -- 
> underground experts united
> https://dataswamp.org/~incal
>



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Adding major-mode selection to new buffer
  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
  0 siblings, 1 reply; 21+ messages in thread
From: Emanuel Berg @ 2022-06-27 23:29 UTC (permalink / raw)
  To: help-gnu-emacs

carlmarcos--- via Users list for the GNU Emacs text editor wrote:

>> They are supposed to be scratch buffers that are not saved,
>> and thus no extension exists.
>
> They are made as named scratch buffers, with a major-mode
> setup. The save button is not available but one can use `C-x
> C-w'.

The *scratch* buffer has major-mode `lisp-interaction-mode',
if you want some other mode for some other buffer, name
it accordingly.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Adding major-mode selection to new buffer
  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
  0 siblings, 1 reply; 21+ messages in thread
From: carlmarcos--- via Users list for the GNU Emacs text editor @ 2022-06-28  0:03 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs


Jun 27, 2022, 23:29 by incal@dataswamp.org:

> carlmarcos--- via Users list for the GNU Emacs text editor wrote:
>
>>> They are supposed to be scratch buffers that are not saved,
>>> and thus no extension exists.
>>>
>>
>> They are made as named scratch buffers, with a major-mode
>> setup. The save button is not available but one can use `C-x
>> C-w'.
>>
>
> The *scratch* buffer has major-mode `lisp-interaction-mode',
> if you want some other mode for some other buffer, name
> it accordingly.
>

Have used `test.c' but ended up in `fundamental-mode' instead of `c-mode'.


> -- 
> underground experts united
> https://dataswamp.org/~incal
>



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Adding major-mode selection to new buffer
  2022-06-28  0:03           ` carlmarcos--- via Users list for the GNU Emacs text editor
@ 2022-06-28  0:19             ` Emanuel Berg
  0 siblings, 0 replies; 21+ messages in thread
From: Emanuel Berg @ 2022-06-28  0:19 UTC (permalink / raw)
  To: help-gnu-emacs

carlmarcos--- via Users list for the GNU Emacs text editor wrote:

>> The *scratch* buffer has major-mode
>> `lisp-interaction-mode', if you want some other mode for
>> some other buffer, name it accordingly.
>
> Have used `test.c' but ended up in `fundamental-mode'
> instead of `c-mode'.

emacs -Q

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Adding major-mode selection to new buffer
  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-28  0:28 ` Chris Van Dusen
  2022-06-28 10:21 ` Jean Louis
       [not found] ` <YrrWHhpK7uiKKVb1@protected.localdomain-N5dqNXf--J-2>
  3 siblings, 0 replies; 21+ messages in thread
From: Chris Van Dusen @ 2022-06-28  0:28 UTC (permalink / raw)
  To: carlmarcos; +Cc: Help Gnu Emacs

Check the scratch package to see if it fits your needs. 

https://github.com/ieure/scratch-el

Chris. 

> On Jun 27, 2022, at 17:51, carlmarcos--- via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
> 
> With the following function I can make a new buffer with a name.  Would also 
> like to set the major-mode from the minibuffer.
> 
> Perhaps using `completing-read` 
> 
> (cseq '("sh-mode" "emacs-lisp-mode" "org-mode" "f90-mode" "c-mode" ))
> (csel  (completing-read "Major Mode: " cseq nil t "org-mode"))
> 
> How can I introduce the above functionality in the `workbench' function?
> 
> (defun workbench (&optional name)
>   "Make new buffer with unique name based on NAME."
>   (interactive "s Buffer Name: ")
>   (switch-to-buffer
>    (generate-new-buffer
>     (if (string-blank-p name) "wb" name))))


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Adding major-mode selection to new buffer
  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-28  0:28 ` Chris Van Dusen
@ 2022-06-28 10:21 ` Jean Louis
  2022-06-28 22:05   ` Christopher Dimech
  2022-06-28 22:20   ` Christopher Dimech
       [not found] ` <YrrWHhpK7uiKKVb1@protected.localdomain-N5dqNXf--J-2>
  3 siblings, 2 replies; 21+ messages in thread
From: Jean Louis @ 2022-06-28 10:21 UTC (permalink / raw)
  To: carlmarcos; +Cc: Help Gnu Emacs

* 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.
> 
> Perhaps using `completing-read` 
> 
> (cseq '("sh-mode" "emacs-lisp-mode" "org-mode" "f90-mode" "c-mode" ))
> (csel  (completing-read "Major Mode: " cseq nil t "org-mode"))
> 
> How can I introduce the above functionality in the `workbench' function?
> 
> (defun workbench (&optional name)
>   "Make new buffer with unique name based on NAME."
>   (interactive "s Buffer Name: ")
>   (switch-to-buffer
>    (generate-new-buffer
>     (if (string-blank-p name) "wb" name))))

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.

{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/



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Adding major-mode selection to new buffer
       [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
  0 siblings, 1 reply; 21+ messages in thread
From: carlmarcos--- via Users list for the GNU Emacs text editor @ 2022-06-28 12:40 UTC (permalink / raw)
  To: Jean Louis; +Cc: Help Gnu Emacs

Jun 28, 2022, 10:21 by bugs@gnu.support:

> * carlmarcos--- via Users list for the GNU Emacs text editor <> help-gnu-emacs@gnu.org> > [2022-06-28 01:51]:
>
> 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.
>

Why do you include a period for `lisp-mode' and `markdown-mode'?


> {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/
>



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Adding major-mode selection to new buffer
  2022-06-28 12:40   ` carlmarcos--- via Users list for the GNU Emacs text editor
@ 2022-06-28 18:22     ` Jean Louis
  0 siblings, 0 replies; 21+ messages in thread
From: Jean Louis @ 2022-06-28 18:22 UTC (permalink / raw)
  To: carlmarcos; +Cc: Help Gnu Emacs

* carlmarcos@tutanota.com <carlmarcos@tutanota.com> [2022-06-28 15:41]:
> Why do you include a period for `lisp-mode' and `markdown-mode'?

It may be error on my side. 

> (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")))


-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Adding major-mode selection to new buffer
  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-28 22:20   ` Christopher Dimech
  1 sibling, 2 replies; 21+ messages in thread
From: Christopher Dimech @ 2022-06-28 22:05 UTC (permalink / raw)
  To: Jean Louis; +Cc: carlmarcos, Help Gnu Emacs

> 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.
> > 
> > Perhaps using `completing-read` 
> > 
> > (cseq '("sh-mode" "emacs-lisp-mode" "org-mode" "f90-mode" "c-mode" ))
> > (csel  (completing-read "Major Mode: " cseq nil t "org-mode"))
> > 
> > How can I introduce the above functionality in the `workbench' function?
> > 
> > (defun workbench (&optional name)
> >   "Make new buffer with unique name based on NAME."
> >   (interactive "s Buffer Name: ")
> >   (switch-to-buffer
> >    (generate-new-buffer
> >     (if (string-blank-p name) "wb" name))))
> 
> 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.
How can the code be modified to have filename saved with the following format?

%Y-%m-%d-T%H:%M:%S--<rcd-temp-buffer-name>-<name>.txt


 
> {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/
> 
>



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Adding major-mode selection to new buffer
  2022-06-28 10:21 ` Jean Louis
  2022-06-28 22:05   ` Christopher Dimech
@ 2022-06-28 22:20   ` Christopher Dimech
  2022-06-29 10:47     ` Christopher Dimech
  1 sibling, 1 reply; 21+ messages in thread
From: Christopher Dimech @ 2022-06-28 22:20 UTC (permalink / raw)
  To: Jean Louis; +Cc: carlmarcos, Help Gnu Emacs

> 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.
> > 
> > Perhaps using `completing-read` 
> > 
> > (cseq '("sh-mode" "emacs-lisp-mode" "org-mode" "f90-mode" "c-mode" ))
> > (csel  (completing-read "Major Mode: " cseq nil t "org-mode"))
> > 
> > How can I introduce the above functionality in the `workbench' function?
> > 
> > (defun workbench (&optional name)
> >   "Make new buffer with unique name based on NAME."
> >   (interactive "s Buffer Name: ")
> >   (switch-to-buffer
> >    (generate-new-buffer
> >     (if (string-blank-p name) "wb" name))))
> 
> 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

          (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/
> 
>



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Adding major-mode selection to new buffer
  2022-06-28 22:20   ` Christopher Dimech
@ 2022-06-29 10:47     ` Christopher Dimech
  0 siblings, 0 replies; 21+ messages in thread
From: Christopher Dimech @ 2022-06-29 10:47 UTC (permalink / raw)
  To: Christopher Dimech; +Cc: Jean Louis, carlmarcos, Help Gnu Emacs




> 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/
> > 
> >
> 
>



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Adding major-mode selection to new buffer
  2022-06-28 22:05   ` Christopher Dimech
@ 2022-06-29 10:57     ` Jean Louis
       [not found]     ` <YrwwJ0/FaRxg2Ryn@protected.localdomain-N5j6REm----2>
  1 sibling, 0 replies; 21+ messages in thread
From: Jean Louis @ 2022-06-29 10:57 UTC (permalink / raw)
  To: Christopher Dimech; +Cc: carlmarcos, Help Gnu Emacs

* Christopher Dimech <dimech@gmx.com> [2022-06-29 01:06]:
> How can the code be modified to have filename saved with the following format?
> 
> %Y-%m-%d-T%H:%M:%S--<rcd-temp-buffer-name>-<name>.txt

My variable is this one: rcd-temp-buffer-name ⇒ "RCD TEMPORARY BUFFER"

And I rarely save it as such, but files are connected to temporary
buffers. It is very handy, as it is temporary note, and if I wish to
exit Emacs I will be notified there is maybe still something to be
saved.

You are right, your suggestion is much better for sorting and visual review.

(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 (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))

-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Adding major-mode selection to new buffer
       [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>
  1 sibling, 0 replies; 21+ messages in thread
From: carlmarcos--- via Users list for the GNU Emacs text editor @ 2022-06-29 16:05 UTC (permalink / raw)
  To: Jean Louis; +Cc: Christopher Dimech, Help Gnu Emacs


Jun 29, 2022, 10:57 by bugs@gnu.support:

> * Christopher Dimech <dimech@gmx.com> [2022-06-29 01:06]:
>
>> How can the code be modified to have filename saved with the following format?
>>
>> %Y-%m-%d-T%H:%M:%S--<rcd-temp-buffer-name>-<name>.txt
>>

That format would be very convenient.  How can I add name as well to the `file-name'?


> My variable is this one: rcd-temp-buffer-name ⇒ "RCD TEMPORARY BUFFER"
>
> You are right, your suggestion is much better for sorting and visual review.
>

Have tried it and works really well.  Is the numeric prefix argument really necessary?


> (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 (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))
>
> -- 
> Jean
>
> Take action in Free Software Foundation campaigns:
> https://www.fsf.org/campaigns
>
> In support of Richard M. Stallman
> https://stallmansupport.org/
>



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Adding major-mode selection to new buffer
       [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
  0 siblings, 1 reply; 21+ messages in thread
From: carlmarcos--- via Users list for the GNU Emacs text editor @ 2022-06-29 16:42 UTC (permalink / raw)
  To: carlmarcos; +Cc: Jean Louis, Christopher Dimech, Help Gnu Emacs

Jun 29, 2022, 16:05 by help-gnu-emacs@gnu.org:

Jean, have been trying to include the name in file-name, but I cannot see it being
introduced.

(file-name
             (concat rcd-temp-file-directory
                     (format-time-string "%Y-%m-%d-T%H:%M:%S--")
                     rcd-temp-buffer-name "-" name ".txt"))

>> (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 (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))
>>
>> -- 
>> Jean
>>
>> Take action in Free Software Foundation campaigns:
>> https://www.fsf.org/campaigns
>>
>> In support of Richard M. Stallman
>> https://stallmansupport.org/
>>



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Adding major-mode selection to new buffer
  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
  0 siblings, 1 reply; 21+ messages in thread
From: Jean Louis @ 2022-06-30 13:06 UTC (permalink / raw)
  To: carlmarcos; +Cc: Christopher Dimech, Help Gnu Emacs

* carlmarcos--- via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2022-06-29 19:58]:
> Jun 29, 2022, 16:05 by help-gnu-emacs@gnu.org:
> 
> Jean, have been trying to include the name in file-name, but I cannot see it being
> introduced.
> 
> (file-name
>              (concat rcd-temp-file-directory
>                      (format-time-string "%Y-%m-%d-T%H:%M:%S--")
>                      rcd-temp-buffer-name "-" name ".txt"))

That variable `name' must have some value to work. You need not have
`rcd-temp-buffer-name', you may construct your own file name as you
wish.

But you have to get value for name.

If you wish to be asked for name, then 

(read-file-name "File name: ")

-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 21+ messages in thread

* RE: [External] : Re: Adding major-mode selection to new buffer
  2022-06-30 13:06           ` Jean Louis
@ 2022-06-30 14:37             ` Drew Adams
  2022-06-30 15:07               ` Jean Louis
  0 siblings, 1 reply; 21+ messages in thread
From: Drew Adams @ 2022-06-30 14:37 UTC (permalink / raw)
  To: Jean Louis, carlmarcos@tutanota.com; +Cc: Christopher Dimech, Help Gnu Emacs

> > Jean, have been trying to include the name in file-name, but I cannot
> > see it being introduced.
> >
> > (file-name   (concat rcd-temp-file-directory
> >                      (format-time-string "%Y-%m-%d-T%H:%M:%S--")
> >                      rcd-temp-buffer-name "-" name ".txt"))
> 
> That variable `name' must have some value to work. You need not have
> `rcd-temp-buffer-name', you may construct your own file name as you
> wish.
> 
> But you have to get value for name.
> If you wish to be asked for name, then
> (read-file-name "File name: ")

Rings a bell perhaps?

https://emacs.stackexchange.com/q/72384/105

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [External] : Re: Adding major-mode selection to new buffer
  2022-06-30 14:37             ` [External] : " Drew Adams
@ 2022-06-30 15:07               ` Jean Louis
  0 siblings, 0 replies; 21+ messages in thread
From: Jean Louis @ 2022-06-30 15:07 UTC (permalink / raw)
  To: Drew Adams; +Cc: carlmarcos@tutanota.com, Christopher Dimech, Help Gnu Emacs

* Drew Adams <drew.adams@oracle.com> [2022-06-30 17:39]:
> Rings a bell perhaps?
> 
> https://emacs.stackexchange.com/q/72384/105 👀

👀 Sounds familiar to me. 👀


-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2022-06-30 15:07 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
     [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

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.