From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Christopher Dimech Newsgroups: gmane.emacs.help Subject: Re: Adding major-mode selection to new buffer Date: Wed, 29 Jun 2022 12:47:21 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37988"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Jean Louis , carlmarcos@tutanota.com, Help Gnu Emacs To: Christopher Dimech Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 29 12:49:46 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o6VGT-0009fY-L5 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 29 Jun 2022 12:49:45 +0200 Original-Received: from localhost ([::1]:51676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6VGS-0006B6-Hp for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 29 Jun 2022 06:49:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49102) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6VEk-00060R-KR for help-gnu-emacs@gnu.org; Wed, 29 Jun 2022 06:48:01 -0400 Original-Received: from mout.gmx.net ([212.227.15.19]:55325) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6VEh-0006Wf-G8 for help-gnu-emacs@gnu.org; Wed, 29 Jun 2022 06:47:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656499641; bh=HNPVXAWYZEAVVFJzKkkI2amOTWAxh6mQ37bLfMxNA3M=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=de7nZoOhbeF0vGJcob5y0CHPbzzOkHmTbB5ckqlTsHXXWG6PXU9JW6K4OrF1MkGrO X1a5nSQ6goH4AVf6cpNiPzIQaaLD79fUveDp7vCg0mYWG/ShsTNU8XyS4dcYDC04Br U3lpWftKMDMOzLGC+E6sQRnUuN/4cUCFB9GCIvkk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from [92.251.127.164] ([92.251.127.164]) by web-mail.gmx.net (3c-app-mailcom-bs02.server.lan [172.19.170.129]) (via HTTP); Wed, 29 Jun 2022 12:47:21 +0200 Importance: normal Sensitivity: Normal In-Reply-To: X-UI-Message-Type: mail X-Priority: 3 X-Provags-ID: V03:K1:pNFK83MNeGIH5o2DlO6KoaNKjTi4puxmNIMFDegMgAPKmusMvJ6ONQxGOcfReWdCNBDE8 Fysnu85sXN6298tUcSScBDnHqOduiUZfMrr/E9uejhC08Jf5/96cLTMO+afPeqlSdaMUX/dSlxwz fHL8Az4L2aRei35cTPJldn9U+uTBVw0HvTBn58+C28a0inwrXA/Ms6j8+x7+t0tFjwmPLj+Ee9Sv gC09HMytfSYpzQv2k4gsMJh8epD2S+KBcIb5JfbpT9dN8/SgobRYdMtbj6KZ+77M5Nz/SqFEjk4k 0Y= X-UI-Out-Filterresults: notjunk:1;V03:K0:0UhnBeB6YoI=:F1MCD0zcLTpxTVrVUJklH2 j/xy7ZABrlfLSrYSC/XMe6XKmsXMoSbeuW4M0lKlzSuO1LWtwF1pIoksqV5Ejb7vgXH1ZJH3V e/g8jgNjVu+dahafyAucfQJdCQY1vgHm7fTkdlLybQ+aHDZgt8sZusbhhDp8ArEZvgNjDQBdh GOMC34dwhswsqzXRmEp+aKu93MCfCLyPD+PRonFZfxGwjbNiTqK0azamBUqvPPzFagW4SntcH SJmleyausUGTKQM0GzyX7CnBwfJ8rzFNULhAhpf5uIr+QUt3nVVF0z2x6aJiyqg0cXNI0KIpW GUaXL/0Uu2V5+0MtI88iu7/GDbkJ7yfy5yt6GCO39vYDJ3gtasuIhielwly6CdI4qJZhn1oxy h9OyhXCsJViceP3qOeaiYzP6QgzSqQPkfnlHp/xRzehfKh4u+R4/9m8vNBS4mV8NRVr4sgmGu QsltEuZp8eJDUW9B0ixMdt/SvKeuBUcV75LZAwECY6I8nDpta6LOJMYZQ38RfB53N30lRUj4N MBXDFdrk4vlL8QrzsxNzRd1mSqOvqpEvqdJjiIdftBB8ToLLoWEotU34nGgt5LUnMu26eDtsa 5PMwBBBqM06T2Eqn5xWfSMFKQpm5MY9lW+BpKineWpXkBusXwCZN5rGpPM9B5PrsWf/bW9O/Y BYGrArRH023/UWbUmpZrnSEZRHK3c9LC4j5Sk8QfyXfP6tT+tLk4APLRCQnuEl4LphjmGkOmQ JXmtDdNV4TI/0b43MBya6dRhw+VWZZw8yaqlB+xurnVGZ3Mt5AnTHS10AgypNggc2J71TiQq Received-SPF: pass client-ip=212.227.15.19; envelope-from=dimech@gmx.com; helo=mout.gmx.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:138187 Archived-At: > Sent: Wednesday, June 29, 2022 at 10:20 AM > From: "Christopher Dimech" > To: "Jean Louis" > Cc: carlmarcos@tutanota=2Ecom, "Help Gnu Emacs" > Subject: Re: Adding major-mode selection to new buffer > > > Sent: Tuesday, June 28, 2022 at 10:21 PM > > From: "Jean Louis" > > To: carlmarcos@tutanota=2Ecom > > Cc: "Help Gnu Emacs" > > Subject: Re: Adding major-mode selection to new buffer > > > > * carlmarcos--- via Users list for the GNU Emacs text editor [2022-06-28 01:51]: > > > With the following function I can make a new buffer with a name=2E= =C2=A0 Would also=20 > > > like to set the major-mode from the minibuffer=2E > > >=20 > > 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=2E >=20 > Have noticed that the number 1 is inserted when calling `rcd-temp-buffer= '=2E > This makes a problem when one wants to insert the name when saving This is because you are using (interactive "p") >=20 > (file-name > (if name > (concat rcd-temp-file-directory > (format-time-string "%Y-%m-%d-T%H:%M:%S--") > rcd-temp-buffer-name "-" name "=2Eorg") > (concat rcd-temp-file-directory > (format-time-string "%Y-%m-%d-T%H:%M:%S--") > rcd-temp-buffer-name "=2Eorg"))) ) >=20 >=20 > =20 > > {C-u M-x rcd-temp-buffer RET} will ask for mode to be used > >=20 > > {M-x rcd-temp-buffer RET}} will open new temporary buffer > >=20 > > {M-x rcd-temp-buffer RET}} will open new temporary buffer > >=20 > > {M-x rcd-temp-buffer-ask-name RET} will ask for buffer name > >=20 > > {C-u M-x rcd-temp-buffer-ask-name RET} will ask for buffer name and > > for the mode > >=20 > > Code: > >=20 > > (defvar rcd-temp-buffer-name "RCD TEMPORARY BUFFER") > >=20 > > (defvar rcd-temp-file-directory "~/tmp/") > >=20 > > (defvar rcd-temp-buffer-mode-history nil) > >=20 > > (defvar rcd-temp-buffer-modes '(("adoc-mode" =2E "adoc") > > ("emacs-lisp-mode" =2E "el") > > ("lisp-mode" =2E "=2Elisp") > > ("markdown-mode" =2E "=2Emd") > > ("org-mode" =2E "org") > > ("sql-mode" =2E "sql") > > ("fundamental-mode" =2E "txt") > > ("html-mode" =2E "html"))) > >=20 > > (defun rcd-temp-buffer (&optional name mode) > > "Generate new temporary buffer=2E" > > (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=2Etxt")))) > > (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)) > >=20 > > (defun rcd-temp-buffer-ask-name () > > "Generate new temporary buffer by asking for buffer name=2E" > > (interactive) > > (rcd-temp-buffer > > (read-from-minibuffer "Buffer name: "))) > >=20 > > (global-set-key (kbd "") #'rcd-temp-buffer) > >=20 > > --=20 > > Jean > >=20 > > Take action in Free Software Foundation campaigns: > > https://www=2Efsf=2Eorg/campaigns > >=20 > > In support of Richard M=2E Stallman > > https://stallmansupport=2Eorg/ > >=20 > > >=20 >