40

Use command indent-rigidly, which is bound to C-x TAB by default. You can specify the number of spaces to indent by using a prefix argument, such as C-5 C-x TAB. Or you can invoke the command and then use the left/right arrows to interactively adjust the indent level.


24

Use M-s SPC during Isearch to toggle matching whitespace literally. When matching literally, each SPC char you type is matched individually. (This used to be the default Emacs behavior, BTW.) To configure this as the default behavior customize option search-whitespace-regexp to nil. (M-x customize-option search-whitespace-regexp.) See the GNU Emacs manual,...


24

Would something like this be "easier"? (defun current-line-empty-p () (save-excursion (beginning-of-line) (looking-at "[[:space:]]*$")))


16

According to the EmacsWiki, M-x delete-trailing-whitespace will eliminate all trailing whitespace in a buffer. In Spacemacs, it is bound to SPC x d w by default You can do it automatically for all buffers by adding the following to your init.el: (add-hook 'before-save-hook 'delete-trailing-whitespace) For future reference, you can search for Emacs ...


11

A simple method, close to what you have: (defun current-line-empty-p () (string-match-p "\\`\\s-*$" (thing-at-point 'line)))


9

If you are used python-mode.el C-c > or C-c < to shift blocks left or right


9

What's the idiomatic (or best) way to trim surrounding whitespace from a string? The built-in library subr-x.el has included the inline functions string-trim-left, string-trim-right, and string-trim since Emacs 24.4: (eval-when-compile (require 'subr-x)) (string-trim "\n\r\s\tfoo\n\r\s\t") ; => "foo" Since Emacs 26.1 these inline functions also accept ...


8

The variable org-tags-column controls the distance of tags at the end of the heading. To have just one space, the original poster may wish to consider using: (setq org-tags-column 0) To apply the changes on an existing org file, use C-u C-c C-q The doc-string for org-tags-column, which can be seen by typing M-x describe-variable RET org-tags-column RET ...


8

You can use ClangFormat to achieve this. After installing the clang-format tool, you can use clang-format.el to perform the appropriate actions from emacs. clang-format.el is also available from MELPA. The emacs commands provided are clang-format-buffer and clang-format-region which you can bind as you need. Note that you can customize formatting options by ...


7

First off, since you didn't mention it: Using the same version of Emacs (24.4.1), the behavior you describe can be reproduced in emacs -Q. Secondly, what you are doing should work (AFAICT). It seems that turning on whitespace-mode globally (or even in a mode hook) before visiting a file with a custom whitespace-line-column is what's causing the problem. You ...


7

You might find the hungry-delete package useful. I personally bind C-cdelete to delete whitespace after point, and C-cbackspace to delete whitespace before point like so (global-set-key (kbd "C-c <backspace>") 'hungry-delete-backward) (global-set-key (kbd "C-c <deletechar>") 'hungry-delete-forward) update: as of 12.2018 function definitions ...


7

The buffer-local indent-tabs-mode variable controls this (in general, for any mode). Note that javascript-mode is an alias for js-mode, so there isn't a javascript-mode-hook. (defun my-js-mode-hook () "Custom `js-mode' behaviours." (setq indent-tabs-mode nil)) (add-hook 'js-mode-hook 'my-js-mode-hook)


7

I just added the following to my init.el: (defun prevent-whitespace-mode-for-magit () (not (derived-mode-p 'magit-mode))) (add-function :before-while whitespace-enable-predicate 'prevent-whitespace-mode-for-magit) This basically advises the function whitespace-enable-predicate, which whitespace-mode uses to determine, which buffers should receive global-...


7

There is the string manipulation library s.el where trimming whitespace and newlines at the beginning and the end of a string is implemented as function s-trim. I cite that function here with its dependencies: (defun s-trim-left (s) "Remove whitespace at the beginning of S." (declare (pure t) (side-effect-free t)) (save-match-data (if (string-...


6

The string-rectangle command ( C-x r t) can be used to insert any arbitrary text (spaces included) in a selected region. Let's say you have this block of text and you want to insert 5 spaces in front of all lines. abc def ghi First select a "0 column" region as shown below (the point is on the character 'a' and the mark is in the same column in the ...


6

Ignoring whitespace-mode, there's always: (setq-default show-trailing-whitespace t) and M-x customize-face RET trailing-whitespace RET which might not give you that exact visualisation, but will let you visualise trailing whitespace nevertheless. I also have a keybinding for this: (defun toggle-show-trailing-whitespace () "Toggle `show-trailing-...


6

The documentation in the emacs manual says: Whitespace mode is a buffer-local minor mode that lets you “visualize” many kinds of whitespace in the buffer, by either drawing the whitespace characters with a special face or displaying them as special glyphs. The relevant docstrings contain more information. So let's say we want do display spaces as ·...


6

If you want this to act in any buffer, not just a file-visiting buffer then find-file-hook is not appropriate. (You said "all buffers", but you also spoke of editable/non-editable "files".) If you want it to work in all buffers then this is one solution: (defun my-show-trailing-ws () "Show trailing whitespace in the current buffer, unless it is read-only....


6

Try M-x whitespace-mode to toggle display of space, line breaks, etc. You can set whitespace-style to control what gets displayed. (Try M-x customize-variable whitespace-style to see what options are available.) You might also try: M-x customize-group whitespace, to see all the related options -- whether to turn on whitespace-mode globally, how to display ...


6

Spacemacs uses evil-mode which is a VI emulation layer. Evil-mode adds VI modal editing to spacemacs. In a nutshell modal editing has different modes where keybindings do different things. This is partly so that keybindings can remain short and easy to remember. In essence, the answer to your question is that you enter the space character by switching to ...


5

This should do what you want. Define regexps that match what you want, and faces. Then match the subgroups in the function you add to font-lock-keywords. The subgroups are used to say that you want only the spaces after indenting tabs, and only non-indenting tabs. (defface my-tab '((t (:background "LemonChiffon"))) "..." :group 'faces) (defface my-space '...


5

The built-in CSS mode should support this just fine by giving indent-tabs-mode a non-nil value. Note that spaces will still be used for padding if the number of indentation spaces isn't a multiple of tab-width. The default values of tab-width and css-indent-offset are 8 and 4 respectively, so you'll need two levels of indentation before a tab is inserted. ...


5

Quoting from the manual: The kinds of whitespace visualized are determined by the list variable whitespace-style. Individual elements in that list can be toggled on or off in the current buffer by typing M-x whitespace-toggle-options. You're setting whitespace-style with this code: (setq whitespace-style (quote (face spaces tabs newline space-mark ...


4

There is C-x TAB (bound to indent-rigidly). Give it a prefix argument to indicate how many spaces you wish to indent by, negative removes that many spaces.


4

You should generally start Emacs with emacs -q to make sure it's not your configuration. If that doesn't get rid of it, but emacs -Q does, chances are it's the way your Emacs was packaged or a site file that's used for every user on your system. Additionally to that you can inspect the faces involved by placing point at the highlighted area and doing M-x ...


4

The Emacs Manual (section Special Isearch) says this: By default, incremental search performs lax space matching: each space, or sequence of spaces, matches any sequence of one or more spaces in the text. Hence, "foo bar" matches "foo bar", "foo bar", "foo bar", and so on (but not "foobar"). More precisely, Emacs matches each sequence of space ...


4

I use this quite often: (defun join-line* () "Join this line with the next line deleting extra white space." (interactive) (join-line t)) (global-set-key (kbd "M-j") #'join-line*) ;; just key binding I use…


4

(defun blank-line-p (&optional pos) "Returns `t' if line (optionally, line at POS) is empty or composed only of whitespace." (save-excursion (goto-char (or pos (point))) (beginning-of-line) (= (point-at-eol) (progn (skip-syntax-forward " ") (point)))))


4

You can use skip-syntax-forward to skip non-whitespace. Docstring: (skip-syntax-forward SYNTAX &optional LIM) Move point forward across chars in specified syntax classes. SYNTAX is a string of syntax code characters. Stop before a char whose syntax is not in SYNTAX, or at position LIM. If SYNTAX starts with ^, skip characters whose syntax ...


4

This is a known problem as made evident in a comment in whitespace.el: (defcustom whitespace-display-mappings '( (space-mark ?\ [?\u00B7] [?.]) ; space - centered dot (space-mark ?\xA0 [?\u00A4] [?_]) ; hard space - currency ;; NEWLINE is displayed using the face `whitespace-newline' (newline-mark ?\n [?$ ?...


Only top voted, non community-wiki answers of a minimum length are eligible