From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Will Parsons Newsgroups: gmane.emacs.help Subject: Re: Making a non-ASCII space character visible Date: Mon, 18 Jun 2018 20:12:29 -0400 Message-ID: References: Reply-To: gyliamos@gmail.com NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1529367231 9810 195.159.176.226 (19 Jun 2018 00:13:51 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 19 Jun 2018 00:13:51 +0000 (UTC) User-Agent: slrn/1.0.3 (FreeBSD) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jun 19 02:13:46 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fV4HK-0002Rp-2N for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Jun 2018 02:13:46 +0200 Original-Received: from localhost ([::1]:38136 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV4JR-0005wy-BE for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Jun 2018 20:15:57 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 155 Original-X-Trace: individual.net i2GhwG/TnEI1L2lWYpxYVAwONN4TlBdeUEVtPJty/wNzMEhocW Cancel-Lock: sha1:LTWjtxRpaBhfFpVr3wbd6pWM88o= Original-Xref: usenet.stanford.edu gnu.emacs.help:223084 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:117205 Archived-At: On Sunday, 17 Jun 2018 9:40 PM -0400, Nick Helm wrote: > On Mon, 18 Jun 2018 at 08:28:18 +1200, Will Parsons wrote: > >> I sorry if I seem to be a bit dense here, but if >> global-whitespace-mode doesn't enable whitespace-mode globally, what >> is it good for? > >> So, adding (whitespace-mode 1) to my ~/.emacs file is useless unless I >> add it to a major-mode hook, and that I have to do that for every >> major-mode I use? I can't just say "enable whitespace-mode for all >> buffers unless I say otherwise" then? > >> I'm afraid I'm completely lost here. > >> Apart from how to enable whitespace-mode automatically, I'd like to >> understand how that: >> >> 1) The character u+2007 (8199) has been verified to have been added to >> whitespace-display-mappings. >> >> 2) Even after running manually M-x whitespace-mode and verifying that >> the variable whitespace-mode is now set to t, the display of u+2007 >> doesn't change in the current buffer. > > Think of whitespace-mode and global-whitespace-mode as two different modes. > > Doing M-x whitespace-mode will show whitespace chars only within the buffer that > was current when when you called the command. Doing the same command a second > time will toggle whitespace-mode off again. When a window shows a buffer that has > whitespace-mode active, "ws" (lower case) will appear in the mode-line. > > Doing M-x global-whitespace-mode will show whitespace chars in all buffers (with > a few exceptions). Doing the same command a second time will toggle > global-whitespace-mode off again in all buffers. When global-whitespace-mode is > active, "WS" (upper case) shows in all mode-lines as it is active in all > buffers. > > The two modes work cooperatively, so you can, for example, turn on > global-whitespace-mode everywhere, then toggle whitespace-mode off to hide > whitespace chars in a particular buffer. That makes sense, and is kind of like what I would have expected. > There are also two variables with (confusingly) the same names as the functions > that control the modes, i.e. whitespace-mode and global-whitespace-mode. Ignore > these variables for now, they cannot control the modes, only tell you what state > each mode is in. Yes - I had managed to figure that out. > When enabling the modes from lisp, it works slightly differently. You need to > call the functions `whitespace-mode' and `global-whitespace-mode' with an > argument to turn the modes on and off. For instance, if global-whitespace-mode > is off and you evaluate this (using C-x C-e): > > (global-whitespace-mode 1) > > Emacs will turn the mode on in all buffers. Evaling it again will have no effect > as the mode is already active. To turn it off, you would eval: > > (global-whitespace-mode -1) > > Similarly, if you want to turn on whitespace-mode in a particular buffer, you > need to eval the function within the buffer you're interested in. For example, > evaling this in *scratch* will only turn it on in *scratch*: > > (whitespace-mode 1) > > This is why adding (whitespace-mode 1) to your ~/.emacs file by itself doesn't > work. Emacs has activated the mode in whatever buffer happened to be current > when it started up, which is unlikely to be a buffer you're interested in. So to > active it automatically everywhere all the time, you would add: > > (global-whitespace-mode 1) > > to your ~/.emacs file. Or, if you want to activate it only for specific modes, > you would use a mode hook to turn on whitespace-mode just for buffers that use > that specific mode. > > However, because you want to visualise some non-standard characters, before you > turn on either of the whitespace modes, you need to tell Emacs what you want it > to display. That's what the variable whitespace-display-mappings is for. This is > a global variable, it's value is the same regardless of whether you're using > whitespace-mode or global-whitespace-mode. > > As you've already worked out, you would change this variable to remap the char > you're interested in, but you need to make sure you set the variable before you > turn the mode on. So you would have something like the following in your > ~/.emacs: > > (setq whitespace-display-mappings '((space-mark 32 [183] [46]) > (space-mark 160 [164] [95]) > (space-mark 8199 [164] [95]) > (newline-mark 10 [36 10]) > (tab-mark 9 [187 9] [92 9]))) > (global-whitespace-mode 1) This is valuable information. I see that I got that wrong in that I had: (global-whitespace-mode 1) (setq-default whitespace-style '(face lines-tail tabs trailing)) in the body of my ~/.emacs file, but that I had: (setq custom-file "~/.emacs.d/custom.el") (if (file-exists-p custom-file) (load-file custom-file)) at the very end, and that I had put the setting of whitespace-display-mappings in ~/.emacs.d/custom.el. > In addition to the defaults, this tells Emacs to map FIGURE SPACE (8199) to > CURRENCY SIGN (164) when either whitespace-mode or global-whitespace-mode is > active. BTW, if you want to visualise the FIGURE SPACEs differently you can > change the 164 in (space-mark 8199 [164] [95]) to the codepoint for whatever > char you like. > > That should be all you need to get this working. Normally, you could do all this > through customize, but as pointed out up-thread, this isn't working as expected. > Fortunately, you can do this entirely in your ~/.emacs file with the lines > above, but it might pay to temporarily disable any other settings related to > whitespace in your custom.el and ~/.emacs while you get things working. OK - I have now modified my .emacs file to have the following lines: ------- (setq whitespace-display-mappings '((space-mark 32 [183] [46]) (space-mark 160 [164] [95]) (space-mark 8199 [164] [95]) (newline-mark 10 [36 10]) (tab-mark 9 [187 9] [92 9]))) (global-whitespace-mode 1) (setq-default whitespace-style '(face lines-tail tabs trailing)) ------- I have removed the setting of whitespace-display-mappings that I had previously manually introduced to custom.el, and the only other setting that appears to reference whitespace is the setting (whitespace-tab ((t (:background "#081820" :foreground "darkgray"))) in my custom.el file, which I have now removed. Unfortunately, after making these changes, and having restarted Emacs, there is still no change to the display of u+2007. Despite my frustration about not achieving my aim, I thank you for your very detailed explanation of the relationship between whitespace-mode and global-whitespace-mode, which, although it hasn't actually led me to a solution to my problem, has been very helpful for my understanding of how whitespace-mode works. -- Will