Questions tagged [whitespace]

for questions about handling white or blank spaces. Besides space characters, Emacs is configured to handle the following as white space characters: tabs, indents, newlines that create blank space between text, either horizontally or vertically.

Filter by
Sorted by
Tagged with
26
votes
5answers
12k views

How to shift a selected area of text in Emacs by a certain number of spaces?

I am writing python code so shifting/moving blocks of lines is important to avoid going through each line individually. How can I do this without an add-on? Is there a type of operation keystroke ...
20
votes
3answers
2k views

Match two spaces with incremental search

When searching using: C-s SPC SPC Also matches single spaces. I want to match exactly two space.
13
votes
7answers
3k views

Easiest way to check if current line is “empty” (ignoring whitespace)?

I just want to check if the current line is empty or not (if it contains only whitespace, then I still consider it empty). Here is my initial version: (defun strip-text-properties(txt) (set-text-...
11
votes
2answers
607 views

How can I suppress emacs' display of the final newline in a file?

One of vim's quirks is that it doesn't show an empty line at the end of a file if the file ends with the newline character. This way, if the file doesn't end with a newline, the display is the same, ...
9
votes
2answers
623 views

Override `show-trailing-whitespace` in `diff-mode`

I have show-trailing-whitespace set to t globally in my .emacs file, and this is generally not a problem except for when I'm in diff-mode looking at a patch which has mandatory trailing white space ...
7
votes
3answers
1k views

How to delete all whitespace up to the first non-whitespace character?

I'm looking for an emacs function that will delete all whitespace from the cursor position (including newlines) until the first non-whitespace character. For example, if my cursor is positioned at ...
7
votes
1answer
3k views

“Format Code” like in Eclipse

In Eclipse, I can hit CTRL + SHIFT + F which not only corrects the indentation but also whitespace (for example: c=a +b ; is corrected to c = a + b;) and the line length. I am looking for a similar ...
7
votes
2answers
119 views

Is there a hook that runs for all read only buffers

I want to enable show-trailing-whitespace for editable file and disable show-trailing-whitespace for read only files. I've tried (defun my/read-only-whitespace () (setq-local show-trailing-...
7
votes
2answers
117 views

How to highlight preceeding space-indentation that isn't rounded to current width?

Is there a way to highlight (set the background color for example) the space before a line, when it's indentation isn't aligned to the current indentation-width? 4 spaces indentation for eg: fn ...
7
votes
2answers
215 views

How to automatically adjust whitespace after yanks?

When editing human language text and moving text fragments around, I frequently run into the problem that whitespace moved at the beginning or end of a fragment doesn't fit into the new position. For ...
6
votes
2answers
1k views

What's the idiomatic (or best) way to trim surrounding whitespace from a string?

I'm working with strings which may have any number of prefix and suffix spaces, tabs, newlines, etc. Currently I have this: (replace-regexp-in-string "^[^[:alnum:]]*\\(.*\\)[^[:alnum:]]*$" "\\1" ...
6
votes
1answer
97 views

Whitespace highlighting

I've tried whitespace-mode, but I can't configure it the way I want. There are others, but some of them are obsolete and I don't want to try them all. I always indent via tabs and can't stand ...
6
votes
1answer
521 views

Whitespace-mode tab mark disturb my indentation

I encounter this issue when i set whitespace-style to (face tabs trailing tab-mark) and turn on whitespace-mode. When whitespace-mode is turned off, everything looks well: When whitespace-mode is ...
6
votes
1answer
321 views

Retooling fill-paragraph to append trailing spaces

I'm using emacs as an external editor for mutt, and am hoping to get format=flowed messages to compose properly. The default behavior for fill-paragraph is to end lines without any whitespace, but the ...
6
votes
0answers
465 views

Display tab characters as arrows of varying length

I would like to make tab characters ("\t") display as arrows of varying length, just like in editors such as Notepad++, gedit, Geany, etc. Here is an example with tab width set to 4 and space ...
5
votes
1answer
968 views

Too much whitespace on setting org-mode tags

If I create the following in an org-mode buffer: * one ** two ** three then move point to the line containing "two" and do C-c C-c spam <RET>, I get this: * one ** two ...
5
votes
1answer
445 views

How do I make javascript-mode not turn all 8 spaces into tabs?

This is what javascript-mode generates with standard tabbing (I never hit the space key when making it). I'd like to have the files contain no tab characters. I can't seem to find any option in the ...
5
votes
1answer
275 views

avoiding underlined spaces between two lines

It must be very simple to get rid of but I could not find something addressing the problem : I would like to avoid underlined spaces between two lines. The following screenshot illustrates the problem ...
4
votes
2answers
3k views

How can I visualize trailing whitespace like this?

I've tried to configure whitespace-mode to do what I want but with no luck. I'm trying to achieve the following (see image).
4
votes
1answer
399 views

How to skip forward to first whitespace character?

What is the easiest way to skip forward to the first whitespace character after the current cursor? I used to do it just by searching for a space (when I knew there was one there), but now that seems ...
4
votes
1answer
182 views

distinguish inner consecutive spaces

I'm aware of and use whitespace-mode to great effect. I don't show a glyph/character for spaces because I think it's too noisy and unnecessary. I do highlight trailing spaces red which is great. ...
3
votes
1answer
2k views

Is there a function for removing trailing spaces in a buffer?

Does emacs have a built in function for removing trailing spaces in a buffer? I want to remove trailing whitespace at the end of all the lines in a buffer.
3
votes
3answers
170 views

magit-status does not open, when using (global-whitespace-mode 1)

This problem started happening today when I switched to my desktop computer after a couple months of using my laptop. I updated emacs to 25.3.1, updated all my packages, and downloaded my latest ....
3
votes
1answer
463 views

whitespace-mode ignores whitespace-line-column

In ~/.emacs I've globally enabled whitespace-mode: (require 'whitespace) (setq whitespace-style '(face empty tabs lines-tail trailing)) (global-whitespace-mode t) Example buffer content: -*- fill-...
3
votes
3answers
862 views

Disable removal of trailing whitespace in Emacs

I'm using Emacs 25.1.50 (9.0) on OS X and am starting to get annoyed with the automatic removal of trailing whitespace. I have tried solutions from here, but to no avail as my write-file-functions and ...
3
votes
2answers
556 views

css-mode: use tabs and not spaces

How do I make it so tabs are used instead of spaces when TAB is pressed? I've tried setting indent-tabs-mode to t but no dice. On my other modes, such as php-mode and c-mode, tabs are inserted. CSS ...
3
votes
2answers
212 views

Delete trailing white space from all projectile project files

Problem So the problem is pretty straight forward I'm just trying to get delete trailing spaces from all files in a projectile project. Here's what I've tried so far: (defun projectile-delete-...
3
votes
1answer
56 views

formatting of elisp file is different in emacs and other text editor

I'm having an issue with formatting in that when I'm in emacs, the formatting looks fine: but when the file is viewed with a different text editor, the spaces are different. this only occurs in the ...
3
votes
1answer
80 views

Function to allow select a directory and run a command on its files, descending recursively?

I sometimes work on legacy code, and they have mixture of tabs and spaces. I use whitespace-cleanup function in whitespace.el to clean them up. But I have many files, so i want to run the command on ...
3
votes
1answer
104 views

List modified line numbers in a buffer

Emacs provides a fair few commands (delete-trailing-whitespace, for instance) that can be used to clean up buffers, but sometimes we cannot use them and risk compromising the version history of ...
3
votes
1answer
131 views

How to prevent whitespace cleanup at point?

I have hooked whitespace-cleanup to before-save-hook and there is a timer to auto save buffer every 5 seconds. When i am typing something, or coding in python, I stop once in a while and buffer ...
3
votes
1answer
267 views

Move to goal-column inserting spaces if necessary

I have a bunch of lines of text and I'm trying to insert text starting at a certain column on each line. For example: 'Some text' This is ok 'Another longer text' ask Ram 'weird stuff' ...
3
votes
0answers
375 views

How to delete all white space during save except for final new line

I am aware that it is a good idea to have one blank line at the end of each file. I am also aware that extra white space in a file is bad. Currently in my .emacs file I have (add-hook 'before-save-...
3
votes
0answers
105 views

How to hide the extra period in linum mode when you have whitespace mode enabled?

I have linum mode and whitespace mode enabled. This works great except that I want padding in linum mode (which uses a space) and so, instead of there being a space (or a different colored space as I ...
2
votes
4answers
674 views

How can I stop emacs from highlighting whitespace?

After a recent update, my Perl files are rendered like this: Note that trailing spaces are shown in red and empty lines in yellow. This is happening despite my having the following in my ~/.emacs: (...
2
votes
1answer
501 views

How do you type a space character in Spacemacs?

I was researching editors and I ended up stumbling upon Spacemacs and the fact that it uses the spacebar instead of traditional modifier keys. The documentation claims that this lowers the user's risk ...
2
votes
1answer
108 views

Highlight missing double-space between sentences?

For a while, I've been using sentence-end-double-space: nil. Now I want to get back into the habit of using two spaces to separate sentences. It is the convention for GNU documentation, and it ...
2
votes
1answer
67 views

How can I configure incremental search to put my cursor at the start of whitespace rather than the end?

I just installed a new version of Emacs (24.3.1 through Fedora). For some reason, when I use C-s to search for a single space character, it jumps my cursor to the end of contiguous spaces rather than ...
2
votes
1answer
260 views

Delete trailing whitespace when saving, except certain modes

How can I delete-trailing-whitespace when saving, except for certain modes? With this attempt, whitespace is deleted for all modes, including fundamental-mode, which I'm trying to avoid. (add-hook '...
2
votes
1answer
358 views

Difficulty with query-replace-regexp

I'm having trouble getting query-regex-replace to do what I want. I've read the docs several times and still can't figure it out. Here are a few examples of things I can't figure out how to do with ...
2
votes
1answer
232 views

How to activate whitespace-mode for a cc-mode buffer from .dir-locals.el?

I'd like to enable whitespace-mode from a .dir-locals.el file such that when I open a file managed by cc-mode, I will see trailing spaces highlighted with the whitespace face. I think I'm close. This ...
2
votes
1answer
247 views

How to set whitespace-line-colum per mode?

I'm trying to have whitespace-line-column set to 80 in prog-mode and 100 in web-mode, etc. However when using hooks seems to get ignored, as is always set to 80. (require 'whitespace) (setq ...
2
votes
3answers
937 views

Whitespace issue in spacemacs

It seems that whitespace is no longer visible while editing files, since this github issue. Now I usually end up seeing the whitespace only after I have saved or even commited my files sometimes. ...
2
votes
1answer
435 views

org-mode setting to preserve spacing in SRC code, with verbatim latex output to pdf

Like this post, when I indent within a SRC code block in org-mode, 8 consecutive spaces are converted to a tab. Moreover, when I export to LaTeX 8 consecutive spaces are converted to tabs in the ...
2
votes
2answers
102 views

Automatically insert a space in some C expressions

The corporate rules about indention forces us to surround our if conditions with spaces like this (in a C and C++ codebase) : if (<space>foo == bar<space>) { } Is there any emacs tool ...
2
votes
1answer
90 views

Make spaces show as spaces in minibuffer instead of completion

The default mapping of SPC in minibuffer is (self-insert-command N). However, I prefer SPC to simply type a single space (for instance, in passing arguments to environments and commands within AuCTeX)....
2
votes
1answer
182 views

Weird spacing with whitespace newline mark “↴” [duplicate]

I have my whitespace newline mark set to the "↴" character, (setq whitespace-display-mappings '( (newline-mark 10 [8628 10]) ))...
2
votes
1answer
507 views

Enable whitespace-mode with Prelude in C++-mode

With a vanilla install of Prelude and with C++-mode as my major mode, M-x whitespace-mode no longer shows whitespace characters. I get a message indicating that I am toggling whitespace-mode on and ...
2
votes
2answers
63 views

Convert tabs to spaces when copying text to external applications

I use tabs in C/C++ but want to convert those tabs to spaces when copying code that I'm going to paste into an external program. However, I want the original code to retain tabs. Additionally (if ...
2
votes
0answers
190 views

How to display and format leading spaces (spaces at the beginning of a line) with whitespace-mode?

I want to see all spaces at the beginning of a line as dots. Also tabs and line breaks. So I've set my init.el file as the following: (setq-default indent-tabs-mode nil) (setq whitespace-style '(...