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.

Emacs provides extensive editing, parsing, printing, and programming support for handling white spaces. The in one such feature, which has consolidated blank-mode and many other space functions.

Emacs can clean up spurious characters in buffers without clobbering spacing needs of the underlying programming language syntax.

Emacs also uses the same definitions for determining boundaries between words, sentences, expression, etc., for text selections, insertions, deletions, and general navigation.

Some functions insert customizable visual characters for easy visibility.

Useful link:

141 questions
42
votes
5 answers

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 command to do this?
Vass
  • 713
  • 1
  • 5
  • 12
29
votes
3 answers

Match two spaces with incremental search

When searching using: C-s SPC SPC Also matches single spaces. I want to match exactly two space.
Rovanion
  • 975
  • 7
  • 20
17
votes
7 answers

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-properties 0 (length txt) nil txt) txt) (defun…
Chillar Anand
  • 4,042
  • 1
  • 23
  • 52
12
votes
2 answers

How can I suppress emacs' cursor moving into the empty last line of 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, only with the [noeol] marker in the…
sykora
  • 269
  • 2
  • 10
12
votes
1 answer

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.
vfclists
  • 1,347
  • 1
  • 11
  • 28
10
votes
3 answers

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" my-string)
user23847
  • 101
  • 1
  • 3
9
votes
2 answers

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 for blank context lines. One solution would be to…
b4hand
  • 1,995
  • 1
  • 19
  • 31
9
votes
2 answers

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).
Cezar
  • 193
  • 1
  • 7
8
votes
3 answers

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 the end of the first line: main(arg1, …
Jeff Bauer
  • 861
  • 1
  • 10
  • 22
7
votes
3 answers

emacs command to remove spaces until next parens

I'm looking for a command that deletes automatically deletes spaces up to the next parens: from: (do | (do-something) true) to: (do |(do-something) true)
zcaudate
  • 637
  • 4
  • 14
7
votes
1 answer

"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 tool for Emacs. All I know is C-x h TAB that…
7
votes
2 answers

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-whitespace (not buffer-read-only))) (setq-default…
Moyamo
  • 388
  • 2
  • 7
7
votes
2 answers

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 my_func() { if foo() { ##bar(); …
ideasman42
  • 8,375
  • 1
  • 28
  • 105
7
votes
1 answer

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 , I get this: * one ** two :spam: **…
Croad Langshan
  • 3,192
  • 14
  • 42
6
votes
1 answer

setq require-final-newline not working when setq-default does

I want all my files to end with only one newline, while trimming trailing whitespaces on regular lines. Like so : ($ is newline face) text$ $ last_line$ I use whitespace-cleanup in my init file, like so : (add-hook 'before-save-hook…
John Doe
  • 159
  • 6
1
2 3
9 10