From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: hw Newsgroups: gmane.emacs.help Subject: Re: how to force auto-save of buffers not visiting files, right now? Date: Tue, 22 Mar 2022 08:06:26 +0100 Message-ID: References: <019b7e509c29caa462ff1c30079ce9bfb8cdc668.camel@adminart.net> <87zglq200a.fsf@web.de> <8fffdb6b532a1fc1805229acfcf9510c3afe18ec.camel@adminart.net> <87wngsmdwp.fsf@web.de> <9f32ac59eb1bc186b015c0b6c5b94822e70d4135.camel@adminart.net> <87y2164u5p.fsf@web.de> <9c3935a33573d50e595f37103434db5e29c21063.camel@adminart.net> <87ilsa61tn.fsf@web.de> <37e890d9c251b30d0caf83aa590bca1ad92ec5d4.camel@adminart.net> <8735jd5v9s.fsf@web.de> <6bf426a46e6ec3804d77cf66d6591928c0f38a3f.camel@adminart.net> <87czihqc4u.fsf@zoho.eu> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27923"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.42.4 (3.42.4-1.fc35) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Mar 22 08:07:30 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 1nWYc6-00075G-F3 for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 22 Mar 2022 08:07:30 +0100 Original-Received: from localhost ([::1]:55592 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nWYc4-0001b6-Sk for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 22 Mar 2022 03:07:28 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:41878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nWYbC-0001Zl-2D for help-gnu-emacs@gnu.org; Tue, 22 Mar 2022 03:06:34 -0400 Original-Received: from mo4-p00-ob.smtp.rzone.de ([85.215.255.21]:41771) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nWYb9-00049i-RX for help-gnu-emacs@gnu.org; Tue, 22 Mar 2022 03:06:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1647932787; s=strato-dkim-0002; d=adminart.net; h=References:In-Reply-To:Date:To:From:Subject:Message-ID:Cc:Date:From: Subject:Sender; bh=T930F9Ni/mBjDG22577aZ+SgCnRoof0Sn1kjN2WW6Ug=; b=Vfltyp7tJT+vlU7HMvmH8HNlgzvBZrAeNAVXTwZchoK7S3SVsavcYta6jGnTbJd5Ct CtX0mfHIIRHju8oCzfHCvOekl1Ne3r2Gu+jFhAXh72r1IPHUVa7syJePpJcIzV4NukFI oiCiORODi6dR7Z2b7nhuPQZlDqsNevC4EsXjSjuLP00EX0f134rlrFKsZF4YVlaQBIEi uvmUkYZ4Az10zwEruOeHxKDxPodRQWKYhNFbTTwp+3l9mAVR6mDIDv905GlMOB1gM60I haujbD5P+ORC8feVIpnxKYd5Lw65GmBdalKBVIH7nItAgthzhrWbeQEVJqHRPX2aknm6 FwmA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":JHskdESlcvGJlcww5P8kEdDfB60eDdbwg2z1BLI60U5wCzf09BLZZsSKYxPQaavhGO/kap91D/preyltlNbCaQjwFFfK7TMBMpHc" X-RZG-CLASS-ID: mo00 Original-Received: from [IPv6:2a09:8e40:1b4d:a200:8d35:8a50:4a04:9661] by smtp.strato.de (RZmta 47.41.1 AUTH) with ESMTPSA id U40bf1y2M76RGdX (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate) for ; Tue, 22 Mar 2022 08:06:27 +0100 (CET) In-Reply-To: <87czihqc4u.fsf@zoho.eu> Received-SPF: none client-ip=85.215.255.21; envelope-from=hw@adminart.net; helo=mo4-p00-ob.smtp.rzone.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_NONE=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:136716 Archived-At: On Sun, 2022-03-20 at 09:08 +0100, Emanuel Berg via Users list for the GNU Emacs text editor wrote: > hw wrote: > > > (defun my-perltidy-replace (_) > > "This function replaces the contents of the current buffer with > > the output of perltidy, and makes a backup of the current buffer. > > > > Before and after modifications to contents of buffers are being > > made, all buffers that need to be auto-saved are being > > auto-saved. > > > > The major-mode of the buffer containing the backup is set to > > 'cperl-mode'." > > Emacs thinks > > the second line should not have indentation ... Maybe it was altered during transfer? It isn't indented. > the first line is not a complete sentence .... To me, it's a complete sentence. We'd have to ask some people who are native speakers of English. > and probably "replaces" should be imperative "replace"! Huh? The function /does/ replace the contents. It "shalln't" replace them, if there is even such a word. > > (linum-mode -1) > > This is the only one needed. The wayland version of emacs screws up the display of the line numbers when you have two buffers displayed in the same frame besides each other, at least when you're using sway. Disabling the mode and re-enabling it is a workaround. > > > (auto-save-mode nil) > > Yuk, not needed ... That depends on whether you have auto-save-mode enabled by default or not ... In a function, you can either check whether auto-save-mode is already enabled or not and enable it if it isn't, or just enable it. In any case, it needs to be enabled for the function to do what I want it to do, so enable it. > BTW final args that could be nil (nil is in the > function range) could always be optional and default to > nil, right? > > Here tho it is ugly by all means but also unnecessary since it > _is_ an optional argument, so all good. What do you mean? Not all arguments default to nil, may they be optional or not. > > (linum-mode 1) > > Not as ugly! But as equally unnecessary still pretty ugl- > I mean unnecessary. When programming, I follow the principle that it's better to be more explicit when it serves to make it more clear what the intention is. And I picked '1' as argument rather than 'nil' because it's confusing that something should be enabled rather disabled because the equivalent of FALSE is given as an argument to it. 'Nil' should disable stuff, not enable it. Please think about this example: perl -e 'print "no\n" unless false;' That appears to work, but it leaves you to guess what the intention is. Using just (linum-mode) leaves me to guess and seems confusing. As to optional arguments, I think they are more a disadvantage than an advantage because the programmers have to make sure not to miss specifying all arguments correctly every time they want to use a function. I rather have it that the computer checks the arguments for me and tells me when there are missing ones, or too many. In perl, you can have that. I also gave up statements like array[iterator++] = 'foo'; in favour of either array[iterator] = 'foo'; iterator++; or iterator++; array[iterator] = 'foo'; a long time ago because they are unclear and cost a lot of time when reading the code and thus are a nuisance. If they're prettier, pretty doesn't always win. > > (defun my-transient-copy (_) > > "This function makes a copy of the current buffer to a new > > buffer. The new buffer does not visit a file. Its name is based > > on the name of the current buffer. > > > > The 'auto-save-mode' is enabled for the new buffer, and all > > buffers that need to be auto-saved are being auto-saved right > > away, once before the copy is created and once after." > > Emacs thinks > > Second line should not have indentation > > First line is not a complete sentence > > Probably "makes" should be imperative "make" > > > (interactive "P") > > Interesting, does that work and what does it do?! The function works, yes. Its description tells you what it does. > > (do-auto-save) > > (let ((transient_buffer (generate-new-buffer-name (concat "transient-copy-of-" (buffer-name))))) > > (copy-to-buffer transient_buffer (point-min) (point-max)) > > Here is another example - when the last two args a and b and > > (<= (point-min) a b (point-max)) > > then both formal parameters can be made optional if we had > argument a defaulting to (point-min) and argument b defaulting > to (point-max), right? You're proving my point with this example: With (copy-to-buffer buffer), you copy the region when omitting the arguments. Maybe it's prettier, but it isn't what I wanted. Maybe that's why the description tells you not to omit the arguments. > > (with-current-buffer transient_buffer (auto-save-mode > > nil)) > > Same. Yes, explicitly :)