51

Disable electric-indent-mode: (when (fboundp 'electric-indent-mode) (electric-indent-mode -1)) That works with any Emacs version. This annoyance or shiny-new-feature, depending on your point of view, was introduced as the default in Emacs 24.4. See also this similar post on StackOverflow. (However, it sounds like you are saying the reverse, and that you ...


48

If the mode line shows a (DOS) indicator, click on it twice to cycle to : meaning Unix newlines and then save the file. If you can't click on the mode line or prefer a keyboard-based solution, run the command C-x RET f (set-buffer-file-coding-system) and type unix. This will change the encoding of newlines without changing the encoding of other characters. (...


15

is #+OPTIONS: \n:t what you want? place this line anywhere in your org-file will preserve line breaks


11

The special form which saves and restores the current point and buffer is save-excursion. So you could write your functions as: (defun insert-line-below () "Insert an empty line below the current line." (interactive) (save-excursion (end-of-line) (open-line 1))) (defun insert-line-above () "Insert an empty line above the current line." (...


11

You are confusing a few things, here. First, RET is not a physical (keyboard) key. It is a logical key -- the Emacs way of writing what your physical Return or Enter key typically sends to Emacs: a Control-M character (which Emacs also writes as C-m, when describing the Ctrl + m key sequence). And if your physical Return or Enter key sends something else, ...


8

(This is too long for a comment, and while not literally an answer, I hope it might help the OP.) While Drew's answer covers what you literally want, this is probably not what you need. Point in Emacs is never on a character, it is between characters: Like other positions, point designates a place between two characters (or before the first character, ...


7

On the left side of the modeline, you'll see (DOS). This means that Emacs is viewing the buffer as if it had DOS-style line endings. To view the buffer as if it had Unix-style line endings, use the command revert-buffer-with-coding-system (bound to C-x RET r or C-x C-m r), and select something like utf-8-unix. Then the ^M characters will be visible. ...


6

You can always check what function some keys are bound to using C-h k. For example, if we type C-h k C-e, we see that it is bound to (move-end-of-line ARG); similarly, C-j is bound to (newline-and-indent). In this case, it turns out that C-e C-j is a sequence of two commands rather than a single thing. (The same with C-a C-o TAB.) To bind this to a single ...


5

Bind C-e to a command that puts the cursor one char to the left of the line end. (defun foo (arg) (interactive "p") (end-of-line arg) (unless (bolp) (backward-char))) (global-set-key "\C-e" 'foo) (Although I cannot imagine why you would want to move the cursor there.)


5

Save the file, and Emacs will automatically use the correct newline char when writing the buffer to file, according to the value of buffer-file-coding-system. To know what is the value of buffer-file-coding-system, call describe-variable then buffer-file-coding-system, or run the describe-coding-system command which you can do by clicking the second ...


5

You need (interactive "P") (not "p") to get a raw prefix argument (i.e. the ability to distinguish between C-u and C-u 4). See C-h f interactive. The raw prefix argument for C-- is not (-1), but -. See C-h i g (elisp) Prefix Command Arguments. open-line takes a required argument. (defun advanced-return (&optional arg) (interactive "P") (if (equal ...


5

While erjoalgo's answer is correct, according to the Emacs Wiki Mutliline Regex page, it is not the most efficient answer: To match any number of characters, use this: .* – the problem is that . matches any character except newline. What many people propose next works, but is inefficient if you assume that newlines are not that common in your text: "\\(.\\...


4

Actually, I just noticed I can do this with \(.\|[\n]\)*. For example, [code] $ sudo wpa_supplicant -B -i wlan0 -Dwext -c universitywpa Successfully initialized wpa_supplicant ioctl[SIOCSIWENCODEEXT]: Invalid argument ioctl[SIOCSIWENCODEEXT]: Invalid argument [/code] - (progn (re-search-forward "[[]code]\\(\\(.\\|[\n]\\)*?\\)[[]/code]" ) (match-...


4

To separate paragraphs by a single line all you need is to add an empty line between each paragraph in your org-file like following: First paragraph Second paragraph \\ is only required to add additional empty lines.


3

Maybe something like this: (defun newline-and-indent-same-level () "Insert a newline, then indent to the same column as the current line." (interactive) (let ((col (save-excursion (back-to-indentation) (current-column)))) (newline) (indent-to-column col)))


3

I think the command you want to use is comment-indent-new-line which is normally bound to M-j.


3

Here's another solution: (defun my-org-return (&optional arg indent) (interactive "*p") (dotimes (number arg) (org-return indent))) (define-key org-mode-map (kbd "<return>") 'my-org-return)


3

If you just want to insert newlines, without any automation for indentation or support for soft newlines, then you can use quoted-insert (C-q), which lets you enter any character including control characters. A newline character is C-j, but the Return key sends C-m, so you need to type C-u 1 0 C-q C-j (insert a newline, times 10). If you want to call the ...


3

To see what command a key is bound to at any point, use the key help commands. Type C-h c RET to see what RET is bound to. In a minibuffer, that's minibuffer-complete-and-exit. Because a minibuffer is active, the message will only appear for a brief time; switch to the *Messages* buffer if you haven't had time to read it. The full message you'll see is ...


3

Usually, Tramp shall respect encoding of existing files. For new files, you could set the encoding via C-x RET f utf-8-unix RET. You can choose also another coding system, the important point is to append the -unixsuffix. Read also the Emacs manual about coding systems.


3

This same or similar question was previously asked on stackoverflow: https://stackoverflow.com/questions/24838516/how-to-set-paragraph-spacing-in-emacs Here is a regurgitation of my prior answer: The following code alters the visual display by adding an additional new visual line, but does not actually add new lines to the current document: (aset (or ...


3

Just use C-q C-j after your prefix command. C-q generally instructs emacs to insert the next key sequence verbatim.


2

First, ^M is the carriage-return character, not the linefeed char (that one is ^J. Here is one answer for this part of your question: How to show the line feed chars - ^M in its original form and not as $: By default, ^M characters should be highlighted using face escape-glyph. Are you sure this is what you are seeing? Try customizing that face (M-x ...


2

;; make unix lineendings default (setq default-buffer-file-coding-system 'utf-8-unix)


2

I can fake this via C-hv search-whitespace-regexp It wouldn't be a full solution unless your comment marker character could never occur in any other context (e.g. the string "100%"). For testing select a window of the buffer with the test text, call M-: and paste the following lisp snippet into the minibuffer. (progn (setq-local search-whitespace-regexp ...


2

Select what you want to change, or C-x h to select the whole buffer. Then: M-x flush-lines RET followed by ^$ RET or ^[[:space:]]*$ RET ^[[:space:]]*$ contain the meta-characters: ^ for beginning of string, $ for end of string, [[:space:]]* zero or more spaces. Ergo, if the first two meta-characters are next to each other or if there is one or more ...


2

Newline and tab are both escaped with a single backslash, because they are escape sequences for the read syntax for strings, and not escape sequences for regular expression syntax. Those characters have no escape sequences in regular expression syntax at all -- they must appear literally in the pattern. In double-quoted strings, however, you can use "\n" ...


2

Interactively, you can use replace-regexp for this. Type C-q C-j to insert a newline character in the minibuffer (so you would need to type this twice). In Elisp strings you can use \n to indicate a newline, so you would write (re-search-forward "\n\n") to search for two consecutive newlines. You can then use a replace-match command for the replacement.


1

For current release of emacs (26.1): (setq-default buffer-file-coding-system 'utf-8-unix) Verify with C-h v buffer-file-coding-system. It should say "global value is utf-8-unix".


1

Here's a workaround that displays fci when its needed. Note that while it takes horizontal scroll into account, I couldn't find a hook to run when horizontal scrolling changes. if fci-rule-column isn't set it uses the value for fill-column. (defvar i42/fci-mode-suppressed nil) (make-variable-buffer-local 'i42/fci-mode-suppressed) (defun fci-width-...


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