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.
(format "Hard-coded value is 100%% and the variable is %s" "50%")
(the % signs never need to be escaped with backslashes).
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))
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:
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"))))
I think you're also confused about how dotimes works. From the doc string:
If what you want is just a timestamp, you can use
(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'."
(let ((str (format-time-string ...
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 //...
I'd probably use a different approach, using mapconcat to apply the function and concatenate the results:
(let ((range (number-sequence 1 20)))
(format "%03d" (* x y)))
range " "))
This returns the string that you can insert or whatever else.
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 ...
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))
You need to format your numbers with the leading zeros if you want them:
(format "%03d" 3)
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".
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.
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.