Hot answers tagged

7

Using the built-in cl-lib package, you can write the following: (eval-when-compile (require 'cl-lib)) (cl-decf (nth 1 x)) Alternatively, in vanilla Elisp: (setf (nth 1 x) (1- (nth 1 x))) Be careful, though, to avoid modifying quoted constant lists such as '(3 6) in-place, as doing so modifies the constant globally and may cause the code to behave ...


3

For numeric calculation there is a parallel universe within Elisp: Calc. The division operator / within defmath works with the floating numbers of Calc. Nevertheless, the interface of Calc with the Elisp world is a bit complicated. You need to convert floating point numbers to strings. These strings are then converted by Calc to their Calc-internal ...


3

The following Elisp code demonstrates how you can define your own wrapper macro with-float/ that treats all explicit occurences of / in its body as division of floats. Division operators that are used in functions called within the body of with-float/ are the original operators. (defmacro with-float/ (&rest body) "Evaluate BODY with / for float ...


2

You can use org-number-to-letter from org-table.el (requires at least Emacs 26.1 or Org 9.1.9?) (require 'org-table) (org-number-to-letters 26) ;; => "Z" (org-number-to-letters 52) ;; => "AZ" And type C-M-% (query-replace-regexp) with [0-9]+ → \,(org-number-to-letters \#&) If you need to do the search-and-replace from Lisp, use re-search-...


2

104 would be cz I think. Using org mode eval setup:-- I suspect there are better choices fr functions but I'm an elisp learner. These conversions might be more appropriates in your code in that there's less if/thens based on ranges. #+begin_src emacs-lisp (setq c 104) (setq lsc (char-to-string (+ (% (- c 1) 26) (string-to-char "a")))) (setq msc (...


1

Just tinkering, you can use car and cdr too. I'm sure someone will comment on whether this is good or bad. (let ((v 99) (p 3) (l (list 1 2 3 4))) (setcar (nthcdr p l) (+ (car (nthcdr p l)) v)) l) ;; => (1 2 3 103)


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

... a way to search for and delete numerals above a certain value I think column-based solutions make more sense in this case but, just for fun, here's an interactive way you could delete numerals above a certain value using search-and-replace: M-x replace-regexp RET \b\([0-9]\{6,\}\)\b RET \,(if (> \#1 164000) "" \1) RET Which will turn your example ...


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