From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: How users start programming in Emacs Lisp... Date: Sun, 30 May 2021 22:48:12 +0300 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21289"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0.7+183 (3d24855) (2021-05-28) Cc: help-gnu-emacs@gnu.org To: Christopher Dimech Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun May 30 21:53:38 2021 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 1lnRVB-0005IV-EH for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 30 May 2021 21:53:37 +0200 Original-Received: from localhost ([::1]:45532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnRVA-0002W3-8q for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 30 May 2021 15:53:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49544) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnRUP-0002Vt-HJ for help-gnu-emacs@gnu.org; Sun, 30 May 2021 15:52:49 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:49791) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnRUJ-00080A-UZ for help-gnu-emacs@gnu.org; Sun, 30 May 2021 15:52:49 -0400 Original-Received: from localhost ([::ffff:102.86.7.33]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 00000000000AE2D6.0000000060B3ED05.000069AE; Sun, 30 May 2021 12:52:36 -0700 Mail-Followup-To: Christopher Dimech , help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 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:130342 Archived-At: * Christopher Dimech [2021-05-30 20:22]: > I am having some problem figuring out what the following does, having format > repeated twice. > > (format format ": " name) It could be all simpler, it just adds the sub-name to the main name. M-x rcd-temp-buffer would create *RCD TEMPORARY BUFFER: 1* but (rcd-temp-buffer "Lisp") would create *RCD TEMPORARY BUFFER: Lisp* Myself I don't know why I made it so complex, but it just works and I use temporary or scratch buffers that way often. Simpler way to open temporary buffer is just: C-x b NAME-OF-YOUR-BUFFER but when function is tied to key binding it becomes simple, press F5 or other key how you bind it, and you are already in clean empty new temporary buffer. Or invoke C-u prefix to be asked for the mode. As Eduardo mentioned maybe it is good to keep those notes, but because in my mind there is distinction on what is temporary and what is not, for me it is fine that way as I use the database and it is trivial to make a function to just open quickly buffer, write anything and have it saved for future. So I made this one... (defun hyperscope-quick-emacs-lisp () (interactive) (let* ((id (hlink-add-generic (concat "Emacs Lisp: " (rcd-timestamp-literate)) "" 50 33)) (template (rcd-db-get-entry "hlinktypes" "hlinktypes_template" 50 hs-db))) (when template (rcd-db-update-entry "hyobjects" "hyobjects_text" id template hs-db)) (hyperscope-edit-with-mode id "hyobjects_text"))) The "name" of the note should be something quick: (concat "Emacs Lisp: " (rcd-timestamp-literate)) ⇒ "Emacs Lisp: Sunday, May 30 2021, 22:21:26" Function `hlink-add-generic' just adds generic object with type 50 (Emacs Lisp in description, text and report of the object) with the parent node 33 which is "Emacs Lisp" set or category. A type can have a template, why not, it is inserted as value of the column "hyobjects_text", and finally edited in the last line. Automatic saving is not a big deal, and automatic revision system also. What really matters is integration that brings speed to user without thinking, and so the workflow is: 1. Press F5, edit Emacs Lisp (forget about anything else) When editing database stuff, then things like byte compiling will not work as it is not tied to buffer, but is not impossible to byte compile and keep what is compiled in the database. I did not manage to make it. I am aware that little of this makes sense to people who edit mostly files. Some functionality can be for files: ;;;; ↝ 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) (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-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) (auto-save-mode 1) (funcall (intern mode)))) (defun rcd-temp-buffer-destroy-em () (interactive) (kill-matching-buffers "RCD TEMPORARY BUFFER")) Then calling `rcd-temp-file' with C-u prefix will create and save the file with chosen mode, it will automatically generate name based on the time stamp and it will be in the chosen mode, like: /home/data1/protected/tmp/Sunday-May-30-2021-22:44:11.sql Defining a key globally: (global-set-key [f5] 'rcd-temp-file) That could be one way to just press a key like F5 and to create a note with the timestamp on a file system without thinking of its file name, opening of file, saving, etc. -- 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/