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.
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,...
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 ...
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.
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 ...
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 ...
Ignoring whitespace-mode, there's always:
(setq-default show-trailing-whitespace t)
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 ()
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-...
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 ...
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 ...
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 ...
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 ...
The buffer-local indent-tabs-mode variable controls this (in general, for any mode).
(defun my-js-mode-hook ()
"Custom `js-mode' behaviours."
(setq indent-tabs-mode nil))
(add-hook 'js-mode-hook 'my-js-mode-hook)
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
The relevant docstrings contain more information. So let's say we
want do display spaces as ·...
This is a feature of electric-indent-mode (which is on by default in recent versions of Emacs). The behaviour is hard-coded in electric-indent-post-self-insert-function.
I think that very few people would actually want what you're asking for (i.e. that trailing whitespace is introduced automatically, and then left there). It's rather more common for people ...
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))
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.
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....
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 ...
After a good bit of digging and learning some features of Emacs Lisp, I managed to make a hack which produces the effect that I desire. I imagine that I'm not the only one who wants to leave trailing whitespace (at least in some scenarios), so here it is:
;; Hack to leave trailing whitespace
(eval-after-load 'electric '(fset 'electric-indent-post-self-...
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 '...
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 ...
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 ...
There is the command just-one-space which collapses all whitespace around the point down to a single space character. It works in any mode, not just paredit. By default it's bound to M-SPC, which can be hard to type since most window managers have a keyboard shortcut there that opens a menu. You can instead type Esc SPC.
IMHO the standard way is:
Go to the top of your buffer.
Type C-M-% for query-replace-regexp.
Input ^\s-+ as regular expression and RET. (See explanation below.)
Leave the replacement string empty, i.e., press RET again.
You are prompted by query-replace-regexp in the minibuffer.
Press ! to perform all replacements at once.
Explanation of the regular ...