From: Dominik Vogt <dominik.vogt@gmx.de>
To: zsh-users@zsh.org
Subject: Re: line continuation with sed
Date: Fri, 14 Oct 2022 18:15:05 +0100 [thread overview]
Message-ID: <Y0mZGRVtYcQtDFpK@localhost> (raw)
In-Reply-To: <2038562980.2864233.1665746341406@mail.virginmedia.com>
[-- Attachment #1: Type: text/plain, Size: 1336 bytes --]
On Fri, Oct 14, 2022 at 12:19:01PM +0100, Peter Stephenson wrote:
> You can configure a number of editors to show this up. In emacs,
> for example, I use:
>
> (setq-default show-trailing-whitespace t)
>
> to show it for all modes, since it's often useful and at worst
> a minor distraction.
Decades ago Paul D. Smith posted the attached script
"rm-tspaces.el" to the fvwm-workers mailing list: When you try to
save a buffer with trailing whitespace, it asks you whether you
want to remove them before saving. Very handy. (Can also be
configured to do this automatically.)
My configuration:
-- ~/.emacs --
;; Removes all trailing whitespace at the end of all lines--this setting
;; makes it ask you by default.
;;
(require 'rm-tspaces)
(setq-default rm-trailing-spaces 1)
;; Turn it on unconditionally for various programming modes
;;
(add-hook 'emacs-lisp-mode-hook 'rm-trailing-spaces-always)
(add-hook 'cperl-mode-hook 'rm-trailing-spaces-always)
(add-hook 'c-mode-common-hook 'rm-trailing-spaces-always)
(add-hook 'makefile-mode-hook 'rm-trailing-spaces-always)
;; Turn it off unconditionally in other places
;;
(add-hook 'message-mode-hook 'rm-trailing-spaces-never)
(add-hook 'nnfolder-save-buffer-hook 'rm-trailing-spaces-never)
-- snip --
Ciao
Dominik ^_^ ^_^
--
Dominik Vogt
[-- Attachment #2: rm-tspaces.el --]
[-- Type: text/plain, Size: 3639 bytes --]
;; rm-tspaces.el: Automatically clean trailing whitespace from buffers.
;;
;; Copyright (C) 1995 Paul D. Smith <psmith@BayNetworks.com>
;;
;; This file requires Emacs 19 or above. It should work with both Emacs
;; and XEmacs. Use (require 'rm-tspaces) to load this file (don't
;; autoload it).
;;
;; For user-invoked whitespace cleanup, the function rm-trailing-spaces
;; can be bound to a key or invoked via M-x.
;;
;; The variable rm-trailing-spaces controls behavior when the buffer is
;; saved. By default nothing is done. See the documentation of this
;; variable for details.
;;
;; The variable rm-trailing-spaces is buffer-local. Use setq-default to
;; set the default value for all buffers. Use setq to override the
;; default value for a particular buffer. If you're going to put the
;; setq in a hook, use the handy hook functions at the end of this file
;; to avoid having to write your own.
;;
;; For example, to be asked about removal for all buffers, except
;; automatically remove spaces in C files, try something like this:
;;
;; (require 'rm-tspaces)
;; (setq-default rm-trailing-spaces 1) ; any non-nil, non-t value
;;
;; (add-hook 'c-mode-hook 'rm-trailing-spaces-always)
;;
;; Note the user is only queried when there is actually trailing
;; whitespace in the buffer (e.g., the buffer would be modified).
;;
;; 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 2, or (at your option)
;; any later version.
;;
;; Changes:
;; 1.2 - Add version info.
;; Add simple functions to make installing in hooks simpler.
(defvar rm-trailing-spaces nil
"*Value of t says silently remove all trailing spaces when a file is saved.
Non-nil but not t says ask user whether to remove trailing spaces or not.
nil means don't remove trailing spaces.")
(make-variable-buffer-local 'rm-trailing-spaces)
;; What are we?
;;
;(defconst rm-tspaces-version (substring "$Revision$" 11 -2)
; "$Id$")
(defun rm-trailing-spaces-internal ()
"Deletes trailing whitespace from all lines in the current buffer."
(if (and (not buffer-read-only) rm-trailing-spaces)
(save-excursion
(goto-char (point-min))
(if (or (eq rm-trailing-spaces t)
(and (re-search-forward "[ \t]$" nil 1)
(y-or-n-p
(format "Remove trailing spaces in buffer %s? "
(buffer-name)))))
(list
(while (< (point) (point-max))
(end-of-line nil)
(delete-horizontal-space)
(forward-line 1))
(end-of-line nil)
(delete-horizontal-space))
)))
nil) ; indicates buffer-not-saved for write-file-hooks
(defun rm-trailing-spaces ()
"Deletes trailing whitespace from all lines in the current buffer."
(interactive "*")
(message "Deleting trailing spaces... ")
(let ((rm-trailing-spaces t))
(rm-trailing-spaces-internal))
(message "Deleting trailing spaces... done"))
;; Apply this function automatically to all buffers before they're saved.
;;
(add-hook 'write-file-hooks 'rm-trailing-spaces-internal)
;; Provide some simple functions for inclusion in hooks variables
;;
(defun rm-trailing-spaces-never ()
"Don't automatically delete trailing whitespace in this buffer."
(setq rm-trailing-spaces nil))
(defun rm-trailing-spaces-ask ()
"Ask before deleting trailing whitespace in this buffer."
(setq rm-trailing-spaces 1))
(defun rm-trailing-spaces-always ()
"Always automatically delete trailing whitespace in this buffer."
(setq rm-trailing-spaces t))
(provide 'rm-tspaces)
;; rm-tspaces.el ends here
next prev parent reply other threads:[~2022-10-14 17:18 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-13 18:25 Ray Andrews
2022-10-14 6:35 ` Lawrence Velázquez
2022-10-14 11:20 ` Dominik Vogt
2022-10-14 15:44 ` Ray Andrews
2022-10-14 17:10 ` Dominik Vogt
2022-10-14 20:38 ` Lawrence Velázquez
2022-10-14 22:26 ` Ray Andrews
2022-10-14 10:57 ` Marc Chantreux
2022-10-14 11:19 ` Peter Stephenson
2022-10-14 17:15 ` Dominik Vogt [this message]
2022-10-14 22:21 ` Ray Andrews
2022-10-15 2:34 ` Aaron Schrab
2022-10-15 2:57 ` Ray Andrews
2022-10-15 5:08 ` Bart Schaefer
2022-10-15 16:53 ` Ray Andrews
2022-10-17 1:07 ` Bart Schaefer
2022-10-17 3:40 ` Ray Andrews
2022-10-17 4:20 ` Bart Schaefer
2022-10-17 9:19 ` Pier Paolo Grassi
2022-10-17 9:24 ` Pier Paolo Grassi
2022-10-17 9:31 ` Pier Paolo Grassi
2022-10-17 16:11 ` Bart Schaefer
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y0mZGRVtYcQtDFpK@localhost \
--to=dominik.vogt@gmx.de \
--cc=zsh-users@zsh.org \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
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 NNTP newsgroup(s).