unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Is there any local variable to avoid asking me to save buffer on kill-buffer?
Date: Mon, 16 Dec 2024 19:13:16 +0300	[thread overview]
Message-ID: <Z2BRnFRInLgGzGSU@lco2> (raw)
In-Reply-To: <jwv8qsfptd2.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 602 bytes --]

* Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2024-12-16 18:02]:
> > I have bunch of temporary buffers which I regularly use, like 160
> > times in 8 days, and as they are truly temporary I do not want to
> > answer the question on `C-x k' yes/no/save?
> 
> AFAIK Emacs doesn't ask confirmation to kill "temporary buffers", so
> I think the question is: what do you mean by "temporary buffers"?

They are programmed, I press F5 and get new temporary buffer, it is
related to the file name, but file is really not important.

New buffer simply.

-- 
Jean Louis

[-- Attachment #2: rcd-temp-buffer.el --]
[-- Type: text/plain, Size: 5710 bytes --]

;;; rcd-temp-buffer.el --- RCD Temporary Buffer  -*- lexical-binding: t; -*-

;; Copyright (C) 2016-2024 by Jean Louis

;; Author: Jean Louis <bugs@gnu.support>
;; Version: 0.1
;; Package-Requires: (rcd-utilities)
;; Keywords: convenience tools
;; URL: https://        NOT YET rcd-temp-buffer-el.html

;; This file is not part of GNU Emacs.

;; This program is free software: you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;;; Change Log:

;;; Code:

;;; RCD TEMPORARY BUFFERS

(defvar rcd-temp-buffer-name "RCD TEMPORARY BUFFER")
(defvar rcd-temp-buffer-session-count 0)
(defvar rcd-temp-buffer-list 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-next ()
  "Switch to next available temporary buffer."
  (interactive)
  (let ((rcd-temp-buffer-list (reverse (rcd-list-matching-buffers rcd-temp-buffer-name))))
    (cond ((and rcd-temp-buffer-list
		(member (current-buffer) rcd-temp-buffer-list))
	   (switch-to-buffer (next-circular-list-item rcd-temp-buffer-list (current-buffer))))
	  ((and rcd-temp-buffer-list (switch-to-buffer (car rcd-temp-buffer-list))))
	  (t (rcd-warning-message "No temporary buffers")))))

(defun rcd-temp-buffer-destroy-em ()
  "Destroy all temporary buffers."
  (interactive)
  (kill-matching-buffers rcd-temp-buffer-name))

(defun rcd-temp-buffer (&optional name mode)
  "Generate new temporary buffer.

In Emacs, you can effortlessly generate a new temporary buffer to use
for various purposes. A temporary buffer is essentially a buffer that
exists temporarily in your current Emacs session and gets discarded once
you close it. This feature is particularly handy when you want to
quickly jot down notes, brainstorm ideas, or experiment with some code
without cluttering your existing buffers.

Standard temporary buffer named \"*scratch*\" is specifically designed
for temporary use.

Once you have created the temporary buffer, you can freely modify it,
insert text, execute Emacs commands, or write code within it. It behaves
just like any other Emacs buffer. Moreover, you can switch between this
temporary buffer and other buffers in your Emacs session using the usual
buffer-switching commands like \"C-x b\" or \"C-x o\". This flexibility
allows you to seamlessly navigate between different buffers while
working on your project.

Furthermore, Emacs offers a multitude of features and functionalities
that you can leverage within temporary buffers. You can customize your
temporary buffer's major mode to suit your specific needs, enabling
syntax highlighting, indentation, and other language-specific
functionalities. This ensures that your temporary buffer provides an
environment tailored to your current task, whether it's writing prose,
coding, or organizing information.

Temporary buffers in Emacs are incredibly versatile and create a dynamic
workspace where you can experiment, brainstorm, and iterate without
being confined to a particular document or file. They seamlessly
complement Emacs's overall philosophy of flexibility and extensibility,
making it a powerful text editor for handling various projects and
workflows."
  (interactive)
  (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)
    (save-buffer)
    (setq rcd-temp-buffer-session-count (1+ rcd-temp-buffer-session-count))
    (rcd-general-log (concat "Opened " buffer-file-name) nil 1 nil nil nil 13)
    (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"))))
    (rcd-temp-buffer-minor-mode)
    buffer-file-name))

(defun rcd-temp-buffer-ask-name ()
  "Generate new temporary buffer by asking for buffer name."
  (interactive)
  (rcd-temp-buffer
   (rcd-ask-get "Buffer name: ")))

(defun rcd-show-prominently (text)
  "This function was meant to make better presentation of the TEXT."
  (let ((buffer (rcd-temp-buffer nil "*RCD Showing Prominently*")))
    (switch-to-buffer buffer)
    (insert text)))

(defun rcd-temp-buffer-kill-current ()
  "Kill current buffer without asking."
  (interactive)
  (let ((buffer-name (buffer-name (current-buffer))))
    (kill-matching-buffers-no-ask (regexp-quote buffer-name))
    (rcd-message "Killed: %s" buffer-name)))

(define-minor-mode rcd-temp-buffer-minor-mode
  "A minor mode for RCD temporary buffers."
  :init-value nil
  :lighter "RCD Temp Buffer Mode"
  :keymap (let ((map (make-sparse-keymap)))
            (define-key map (kbd "C-x k") #'rcd-temp-buffer-kill-current)
	    (define-key map (kbd "C-<f4>") #'kill-buffer)
            map))

(global-set-key (kbd "<f5>") #'rcd-temp-buffer)

(provide 'rcd-temp-buffer)

;;; rcd-temp-buffer.el ends here

  reply	other threads:[~2024-12-16 16:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-16  6:59 Is there any local variable to avoid asking me to save buffer on kill-buffer? Jean Louis
2024-12-16  7:14 ` Jean Louis
2024-12-16 12:04   ` Tassilo Horn
2024-12-16 12:25     ` Eduardo Ochs
2024-12-16 15:00 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-12-16 16:13   ` Jean Louis [this message]
2024-12-16 19:39     ` Suhail Singh
2024-12-16 21:02       ` Jean Louis
2024-12-16 21:26         ` Suhail Singh
2024-12-17  4:05           ` 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=Z2BRnFRInLgGzGSU@lco2 \
    --to=bugs@gnu.support \
    --cc=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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).