Hot answers tagged

17

Re-writing this answer gives another solution: (format-spec "%a %a %a %b %b %b" (format-spec-make ?a "a" ?b "b")) Edit: Another format-spec solution: As Malabarba gives another solution in comments: (format-spec "%a %a %a %b %b %b" '((?a . "a") (?b . "b"))) Edit 2: Evaluation before substitution: ...


15

Magnar Sveen's string manipulation library s.el provides a variety of ways to do this. For example: (require 's) (s-format "${name} ${name} ${name}" 'aget '(("name" . "test"))) ;; ==> "test test test" Note that s-format can take any replacer function, but provides special handling for aget, elt, and gethash. So you could use a list of tokens and ...


6

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 value is 100%% and the variable is %s" "50%") (the % signs never need to be escaped with backslashes).


5

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-file-name argument is defaulted if absent when calling the function clang-format-region from clang-format.el: (unless assume-file-name (setq assume-file-...


5

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 a variable or compute it with a function call, etc. (let ((best-day-ever '(2017 8 21))) (apply #'format "%04d-%02d-%02d" best-day-ever))


4

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) (insert (format "%3d " (* (1+ x) (1+ y))))) (insert (format "\n")))) UPDATE I think you're also confused about how dotimes works. From the doc string: (...


3

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 your init file: (if (version<= "27.1" emacs-version) (global-so-long-mode 1)) Edit: If you’re using an old version of Emacs, then the easiest ...


3

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 follows: %<field><flags><width><precision>character where field is [0-9]+ followed by a literal dollar "$", flags is [+ #...


3

s.el's s-lex-format is really what you want, but if you want to actually be able to put code inside the substitution blocks and not just variable names, I wrote this as a proof of concept. (defmacro fmt (str) "Elisp string interpolation for any expression." (let ((exprs nil)) (with-temp-buffer (insert str) (goto-char 1) (while (re-...


3

Not a general-purpose, but will solve your case: (apply 'format "%s %s %s" (make-list 3 'a)) Using provided example: (apply 'format (concat " * - :raw-html:`<img width=\"100%%\" " "src=\"http://xxx.xxx/images/languages/" "staff/%s.jpg\" alt=\"%s.jpg\"/>` - .. _%s:") (make-list 3 'some-image)) ...


3

I guess internally this uses the function 'format' so you can use %% to produce one %


3

If what you want is just a timestamp, you can use (defvar user-time-format (eval-when-compile (or (getenv "STRFTIME") "%Y-%m-%d %a %H:%M:%S %Z")) "The time format for the user to set.") (defun user-time-format (&optional insert) "Return or insert the time string according to `user-time-format'." (interactive "P") (let ((str (format-time-string ...


2

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 no valid c source code: the obvious: comment lines are not marked as comments. This is fixed easy with search and replace. Type: M-x query-replace-regexp RET //...


2

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 (lambda (x) (format "%03d" (* x y))) range " ")) range "\n")) This returns the string that you can insert or whatever else.


2

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 found from the docstring of diary-block: (diary-block M1 D1 Y1 M2 D2 Y2 &optional MARK) Block diary entry. Entry applies if date is between, or ...


2

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))) A macro form of that: (defmacro dformat (date) `(format "%04d-%02d-%02d" ,@date)) (dformat (2017 8 21))


2

You can open your file with M-x find-file-literally. Moreover you can use the vlf package https://github.com/m00natic/vlfi


1

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 | 7 | 8 | 9 | |---+----+----+----+----+----+----+----+----+----+----| | 0 | 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | | 1 | 01 | 02 | 03 | 04 | 05 | 06 ...


1

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 string "01" and recognizes it as a number (integer) and stores it in the list. Then it promptly forgets how the number was represented - as "1" or "01" or "000001". ...


1

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. The usual solution in Emacs is to use M-x calc. Type d 6 in the calc buffer to run calc-hex-radix (or d r to enter any supported radix value), and then all numbers will be displayed in hex. In ...


1

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)) apply applies a list of arguments to a given function.


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