Hot answers tagged

5

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

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

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-...


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

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))


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