Skip to main content
26 votes
Accepted

Result of arithmetic evaluation in buffer, not echo area

Short version: yes Instead of C-x C-e to evaluate the expression, give it a prefix argument. C-u C-x C-e will print the output to the buffer. How I found this information You can investigate how ...
Dan's user avatar
  • 33.3k
15 votes
Accepted

Insert into specific buffer (not the active buffer)?

Perhaps something like: (with-current-buffer "*scratch*" (insert "Test")) is what you want.
John Kitchin's user avatar
13 votes
Accepted

Insert line above/below

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 ...
Basil's user avatar
  • 12.5k
9 votes

Result of arithmetic evaluation in buffer, not echo area

Bind this to some key. (defun foo () "Replace sexp before point by result of its evaluation." (interactive) (let ((result (pp-to-string (eval (pp-last-sexp) lexical-binding)))) (delete-...
Drew's user avatar
  • 78.5k
9 votes
Accepted

How to insert a formatted string into a specific buffer?

An example of what you are trying to do is contained in the manual. You need either with-current-buffer or save-current-buffer: (with-current-buffer destination-buffer (insert (propertize (format-...
sds's user avatar
  • 6,174
9 votes
Accepted

Insert multiple minus ('-') characters using the universal argument (C-u)

For example, C-u C-u C-q -. You can C-h k C-q for more details.
shynur's user avatar
  • 5,795
8 votes
Accepted

How to insert character or word N times in a buffer or file?

There are many ways to write loops/iterative/repetitive behaviour in elisp. C-hig (elisp)Iteration has the basic options, including dotimes, which is the canonical way to repeat something N times. E....
phils's user avatar
  • 52.4k
6 votes

Insert text or overwrite region

For Emacs setting: (delete-selection-mode t) ; delete seleted text when typing For lisp code, add following line before insert: (if (region-active-p) (delete-region (region-beginning) (region-end))...
AhLeung's user avatar
  • 1,103
6 votes

How to insert character or word N times in a buffer or file?

If you want to insert the character interactively, do C-u 10 X. This will give you XXXXXXXXXX. This repeats the self-insert-command (here, for "X"), 10 times. See the manual node on repeating.
Dayan Sivalingam's user avatar
6 votes
Accepted

How can I insert the backslash character ( \ ) before quotation marks (" ") in Emacs?

This is a feature of paredit. If you look at the minibuffer (the line at the bottom of your Emacs window) when you press \, you'll see you're being prompted for "Character to escape:". The ...
Tyler's user avatar
  • 22.5k
6 votes
Accepted

Way to keybind «» in Emacs

I tried the following, but apparently the quotation mark is interpreted as a macro: [...] You’re almost there, « and » are non-ASCII characters with codes above 127, so you have to use vectors ...
d125q's user avatar
  • 1,473
5 votes
Accepted

How to programmatically insert a string at the end of some file?

You can use the append-to-file and write-region functions, for example, ~ $ echo hello > file.txt ~ $ emacs --batch --eval '(append-to-file "xyz\n" nil "file.txt")' ~ $ cat file.txt hello xyz ~ $ ...
xuchunyang's user avatar
  • 14.7k
5 votes
Accepted

Insert a string from eval-expression without the quotes

Rather than ask M-: to insert the output of the Elisp code, just write the Elisp code that inserts the text you want: Try M-: (insert (format-time-string "%m/%d/%Y")) RET
Stefan's user avatar
  • 26.6k
5 votes
Accepted

How can I type simple underline "_" in Auctex

You can always insert a character literally by typing C-q first (quoted-insert). Many “electric” characters (that's what Emacs usually calls characters whose insertion has extra effects such as ...
Gilles 'SO- stop being evil''s user avatar
5 votes

Key bound to string does not handle some chars in string correctly

global-set-key is just a thin wrapper around define-key, ignoring some error checking it is (defun global-set-key (key def) (define-key (current-global-map) key def)) The documentation for define-...
icarus's user avatar
  • 1,934
5 votes

Quickly inserting a single Greek letter

There are several ways. A key difference is how close H-g a is to typing an actual character α would be if you had that key on your keyboard. For example, you can make H-g a a macro that inserts the ...
Gilles 'SO- stop being evil''s user avatar
5 votes

Result of arithmetic evaluation in buffer, not echo area

If you want to do an arithmetic operation and insert the value into the buffer, but don't care where you do the operation, then you can also do C-u M-: and type the operation info the minibuffer. ...
icarus's user avatar
  • 1,934
4 votes
Accepted

Inserting the plus minus unicode symbol ± as a keyboard macro

With respect to why you saw what you saw: As Eli Zaretskii said in a reply to bug report #33829, the string is interpreted as a keyboard macro, and Emacs "interprets ±, which is a single byte with ...
Drew's user avatar
  • 78.5k
4 votes

Inserting the plus minus unicode symbol ± as a keyboard macro

You can get what you want with (global-set-key (kbd "C-c m") [177]) or if you prefer (global-set-key (kbd "C-c m") [?±]) Another solution uses the package key-chord which allows you to assign ...
Aidan Schofield's user avatar
4 votes
Accepted

Key bound to string does not handle some chars in string correctly

What is going on is that string in Emacs have historically been used in this context for 2 different purposes: sequence of characters. sequence of events. In your case, you're writing what you think ...
Stefan's user avatar
  • 26.6k
4 votes
Accepted

How to create a file from a template if it does not exist or open existing copy?

You could use this version of the function: (defun journal-entry () (interactive) (let* ((daily-name (format-time-string "%Y-%m-%d)")) (journal-path "~/Dropbox (Personal)/journal/") (...
Konstantin Morenko's user avatar
4 votes
Accepted

Spacemacs : insert single character in normal mode

I'm not sure whether there's an Evil-specific way to do this. However, you can write a short Elisp snippet that does this: (defun my/insert-char (char count) (interactive "c\np") (insert-char ...
Arnot's user avatar
  • 671
4 votes

Insert multiple minus ('-') characters using the universal argument (C-u)

To type a minus sign with a numeric prefix argument, you can enter the number by typing the digits: C-u 6 4 - or ESC 6 4 - or M-6 M-4 - or C-6 C-4 - (or a few other combinations). This method doesn't ...
Gilles 'SO- stop being evil''s user avatar
3 votes
Accepted

Cover the active region with a character

(defun cover-active-region (beg end char) "Replace space with CHAR in the region." (interactive (if (use-region-p) (list (region-beginning) (region-end) (read-...
xuchunyang's user avatar
  • 14.7k
3 votes
Accepted

Using quail input-method to insert a string

Using quail-define-rules is overkill (note the rules, plural, in the function name) — an alternative is quail-defrule (one rule...) Directly from my scratch buffer (quail-defrule "á" ["something"]) [...
gboffi's user avatar
  • 614
3 votes

Result of arithmetic evaluation in buffer, not echo area

I prefer to do (also complex) computations in Emacs' calc C-x * * and then copy its result in the buffer where my cursor was with y, q closes the calc buffers and I'm back at this location.
Dieter.Wilhelm's user avatar
2 votes
Accepted

Insert space but don't move point

There's no built-in command to insert a character before the point, presumably because any key binding for it would have to include at least one key stroke in addition to the character, and if you're ...
Gilles 'SO- stop being evil''s user avatar
2 votes
Accepted

The insert function seems to be inheriting the read-only property

It seems it is intentional according to read-only's info manual (info "(elisp) Special Properties"): read-only Insertion next to a read-only character is an error if inserting ordinary text ...
xuchunyang's user avatar
  • 14.7k
2 votes

All Greek letters are capitals, no small Greek letters

As per the comments: lower case and upper case lambda were displayed similarly, but changing the font to DejavuSans resolved the issue.
rpluim's user avatar
  • 5,385

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