[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How users start programming in Emacs Lisp...
From: |
Jean Louis |
Subject: |
Re: How users start programming in Emacs Lisp... |
Date: |
Tue, 1 Jun 2021 00:53:46 +0300 |
User-agent: |
Mutt/2.0.7+183 (3d24855) (2021-05-28) |
* Christopher Dimech <dimech@gmx.com> [2021-05-31 23:31]:
> I would like to be able to decide the name from the mini-buffer.
> How can that be done?
Here is the set of improved functions:
- your main buffer name is in variable `rcd-temp-buffer-name'; your
main buffer name should be something unique, descriptive so that it
can be destroyed easily (when necessarily) or followed up;
- run M-x rcd-temp-buffer-ask-name or bind it to key if you wish to
get asked for sub-name
- use C-u prefix to get asked for mode
- if you have many temporary buffers you maybe wish to browse through
such buffers, because they got their main name, the function M-x
rcd-temp-buffer-next will go through such. Bind it to a simple key
and you can press key and browse through temporary buffers quicker.
;;;; ↝ RCD TEMPORARY BUFFERS
(defvar rcd-temp-buffer-mode-history nil)
(defvar rcd-temp-file-directory "~/tmp/")
(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 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 "" ""))))
(switch-to-buffer (generate-new-buffer buffer))
(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"))))))
(defun rcd-temp-buffer-ask-name ()
"Generate new temporary buffer by asking for buffer name."
(interactive)
(rcd-temp-buffer
(read-from-minibuffer "Buffer name: ")))
(defun rcd-temp-file (&optional name mode)
"Quickly open temporary file.
Using C-u as prefix will ask you for the mode of the file and
will influence the extension.
NAME may be provided programmatically.
MODE may be provided as string programmatically."
(interactive)
(let* ((mode (or mode
(if current-prefix-arg
(let* ((mode (completing-read
"Mode: "
(map-keys rcd-temp-buffer-modes) nil t nil
'rcd-temp-buffer-mode-history)))
mode)
"fundamental-mode")))
(file (concat rcd-temp-file-directory
(or name (format-time-string "%A-%B-%e-%Y-%T."))
(cdr (assoc-string mode rcd-temp-buffer-modes)))))
(find-file file)
(save-buffer)
(funcall (intern mode))))
(defvar rcd-temp-buffer-list nil)
(defun rcd-temp-buffer-next ()
(interactive)
(unless rcd-temp-buffer-list
(setq rcd-temp-buffer-list (reverse (rcd-list-matching-buffers
rcd-temp-buffer-name))))
(let ((rcd-buffer (pop rcd-temp-buffer-list))
(buffer (current-buffer)))
(if rcd-buffer
(if (buffer-live-p rcd-buffer)
(switch-to-buffer rcd-buffer)
(rcd-temp-buffer-next))
(message "No temporary buffers"))))
(defun rcd-temp-buffer-destroy-em ()
(interactive)
(kill-matching-buffers "RCD TEMPORARY BUFFER"))
(defun rcd-list-matching-buffers (query)
"Return list of matching buffers."
(let ((list))
(mapc (lambda (buffer)
(when (string-match query (buffer-name buffer))
(push buffer list)))
(buffer-list))
list))
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
- How users start programming in Emacs Lisp..., (continued)
- How users start programming in Emacs Lisp..., Christopher Dimech, 2021/05/30
- Re: How users start programming in Emacs Lisp..., Jean Louis, 2021/05/30
- How users start programming in Emacs Lisp..., Christopher Dimech, 2021/05/30
- Re: How users start programming in Emacs Lisp..., Jean Louis, 2021/05/30
- How users start programming in Emacs Lisp..., Christopher Dimech, 2021/05/30
- Re: How users start programming in Emacs Lisp..., Jean Louis, 2021/05/30
- How users start programming in Emacs Lisp..., Christopher Dimech, 2021/05/30
- Re: How users start programming in Emacs Lisp..., Jean Louis, 2021/05/30
- Re: How users start programming in Emacs Lisp..., Jean Louis, 2021/05/30
- How users start programming in Emacs Lisp..., Christopher Dimech, 2021/05/31
- Re: How users start programming in Emacs Lisp...,
Jean Louis <=
Re: Fortran Topics (outline-minor-mode, require, fixed format), Jean Louis, 2021/05/29
- Re: Fortran Topics (outline-minor-mode, require, fixed format), Emanuel Berg, 2021/05/29
- Re: Fortran Topics (outline-minor-mode, require, fixed format), Jean Louis, 2021/05/29
- Re: Fortran Topics (outline-minor-mode, require, fixed format), Emanuel Berg, 2021/05/29
- Re: Fortran Topics (outline-minor-mode, require, fixed format), Jean Louis, 2021/05/29
Re: Fortran Topics (outline-minor-mode, require, fixed format), Stefan Monnier, 2021/05/29