Skip to main content
6 votes
Accepted

Percentage "%" in format string

It is indeed %%. If you type C-h f format <RET> you'll pull up the documentation for the format function, which states: Use %% to put a single % into the output. Thus: (format "Hard-coded ...
db48x's user avatar
  • 18.4k
5 votes
Accepted

How can I convert a list of integers to a string?

You can use the apply function to pass a function arguments contained in a list as separate arguments. For example: (apply #'format "%04d-%02d-%02d" '(2017 8 21)) That way you can store the list in ...
Omar's user avatar
  • 4,842
5 votes
Accepted

clang-format malfunctioning(?) Or am I not fully understanding how clang-format works?

I found the same thing (not following my styles as defined in a .clang-format file, which happens to be in the parent directory in my case), and I think that the problem is in the way that the assume-...
William Gallafent's user avatar
4 votes

how to turn off all the formatting and all?

Emacs is often slow on any file with long lines. Improving its performance is not too hard though. I think that the easiest way to improve performance is to enable global-so-long-mode. Add this to ...
db48x's user avatar
  • 18.4k
4 votes
Accepted

How to insert the result of evaluating a sexp in a string?

I would use format instead of concat. For example: (let* ((n (+ 2 value)) (f (if (= 1 n) "fox" "foxes"))) (format "The %d red %s" n f)) You can check the ...
Manuel Uberti's user avatar
4 votes

Percentage sign in `print` and `message`

By running (message (format ...)), you're using the string as a format twice. print takes an object as its parameter, while message takes a format string. Use "%s" as the format and you can ...
choroba's user avatar
  • 2,075
4 votes
Accepted

Emacs lisp format doesn't print to *scratch*?

format generates a string, but it doesn't do anything with it. You probably want to pass the result of format on to something that does: (defun mt () (dotimes (x 20) (dotimes (y 20) (...
Tyler's user avatar
  • 22.4k
3 votes
Accepted

european-calendar-style not working

I think european-calendar-style disappeared at some point (I have it as a commented line in my doemacs file). You should use calendar-date-style: (setq calendar-date-style 'european) This can be ...
JeanPierre's user avatar
  • 7,475
3 votes

Named string substitution?

Since search engines lead me to this page... Reading format documentation, I find the following: A %-sequence other than %% may contain optional field number, flag, width, and precision specifiers, as ...
Whil's user avatar
  • 131
3 votes

Auto format messy code

The code you posted has several issues which needs to be fixed. I will explain a semiautomatic method. This will enable you to fix code which has different issues, with the same method. This code is ...
jue's user avatar
  • 4,596
3 votes
Accepted

How to escape % in emacs

I guess internally this uses the function 'format' so you can use %% to produce one %
YoungFrog's user avatar
  • 3,526
2 votes

How can I convert a list of integers to a string?

Just for fun and profit: (destructuring-bind (year month day) '(2017 8 21) (format "%04d-%02d-%02d" year month day)) An unfortunate use of eval: (eval `(format "%04d-%02d-%02d" ,@ '(2017 8 21))) ...
John Kitchin's user avatar
  • 11.9k
2 votes

Emacs lisp format doesn't print to *scratch*?

I'd probably use a different approach, using mapconcat to apply the function and concatenate the results: (let ((range (number-sequence 1 20))) (mapconcat (lambda (y) (mapconcat (...
choroba's user avatar
  • 2,075
2 votes

how to turn off all the formatting and all?

You can open your file with M-x find-file-literally. Moreover you can use the vlf package https://github.com/m00natic/vlfi
djangoliv's user avatar
  • 3,199
2 votes
Accepted

Representing leading zeroes in a list

You can use this org table formula, format is used to ensure the number's width is 2 and padded with zero, as @sds's answer suggested: #+NAME: addition-table | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | ...
xuchunyang's user avatar
  • 14.6k
2 votes
Accepted

Output the VAR name and its VALUE

Yes, the function you're looking for is format: (defun message-variable-t-nil-value (var) (let* ((val (and (boundp var) (symbol-value var))) (msg (format "The value of `%S' is now %...
Drew's user avatar
  • 78k
2 votes

How can I construct a bash-safe filename from a string?

I found a melpa package which does just that and properly : unidecode (unidecode-sanitize "Une idée nouvelle pour calculer $\\int_0^{\\infty} e^{t^2} \\dd t$") "une-idee-nouvelle-pour-...
B. Pillet's user avatar
1 vote

How to change the formatting of current date in Org agenda

You can write a function that does what you want and add it to org-agenda-finalize-hook (you should read the doc string of this variable with C-h v org-agenda-finalize-hook): #+begin_src elisp :...
NickD's user avatar
  • 30.9k
1 vote
Accepted

Printing formatted args in a buffer

You can use apply #'format on a list of args which you retrieve via &rest args as demonstrated in the following example: (defun tika-instext (bfname fmt &rest args) "Write ARGS to the ...
Tobias's user avatar
  • 33.3k
1 vote
Accepted

Print the contents of a list next to each other

To print the list without 'text-properties' use %s instead of %S. Or if you prefer to print it as a string then use mapconcat, e.g.: (message (mapconcat #'substring-no-properties mylist " "))...
dalanicolai's user avatar
  • 7,865
1 vote

Output the VAR name and its VALUE

Use format. It's the Lisp equivalent of C's printf. Unlike Common Lisp, Emacs Lisp's format specifications are similar to C's, with % as the special character. (defun show-value-of-variable (symbol) ...
Gilles 'SO- stop being evil''s user avatar
1 vote

Representing leading zeroes in a list

TL;DR You need to format your numbers with the leading zeros if you want them: (format "%03d" 3) ==> "003" Details When you type (defvar foo '(00 01 02)) and evaluate it, Emacs reads the ...
sds's user avatar
  • 6,124
1 vote

Why does (format "%x" some-large-number) produces incorrect results?

You've answered your own question -- you're dealing with a number which is larger than most-positive-fixnum and are encountering floating point precision errors as a result. (Refer to https://...
phils's user avatar
  • 51.7k
1 vote

How can I convert a list of integers to a string?

Following is a way to apply a list of arguments to a function, which I believe is what you need: (let ((x '(2017 8 21)) (f (lambda(x y z) (format "%04d-%02d-%02d" x y z )))) (apply f x)) ...
Juancho's user avatar
  • 5,465

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