I am following the emacs lisp tutorial and have just successfully added two numbers:
(+ 111 234)
I enter this in a random buffer (Markdown mode, now, if that matters, but the same happens in *scratch*), and evaluate it with C-x C-e.
However, the bottom line on Emacs does not simply return 345, but it outputs this line:
345 (#o531 #x159 ?r)
When I submit (+ 2 3), the output is 5 (#o5 #x5 ?\C-e).
What is this extra output? It's not mentioned in the tutorial.
This is the same but in octal (#o...) and hexadecimal (#x...), as well as character syntax.
In Emacs Lisp, non-negative integers and characters are the same type:
(integerp ?d)
==> t
(characterp 123)
==> t
Thus you see ?\C-e for 5 because Ctrl-e has the ASCII code 5.
Your ?r is probably a non-ASCII r which has character code 345 in
your locale.
This is documented in Evaluating Emacs Lisp Expressions.
Related
The CLHS describes
22.3.1.4 Tilde Vertical-Bar: Page
This outputs a page separator character, if possible. ~n| does this n times.
I did not find much for page separator character. Trying it out with SBCL 2.0 on MacOS a page separator seems to be the newline (Ascii 0A). This would make it the same as ~%?
Was it something else in the long history of Common Lisp?
For me, the output is ^L - ASCII NP, which, when presented to a printer, finishes the current page and starts on the next page.
It's the #\page character:
CL-USER> #\page
#\Page
CL-USER> (describe *)
#\Page
[base-char]
Char-code: 12
Char-name: Page
CL-USER> (format nil "~|")
"^L"
CL-USER> (aref * 0)
#\Page
If I press C-u C-n the cursor goes down of 4 lines.
Can I make the default universal argument to be another number greater than 4?
There might be a better way to do this, but one possibility is to create your own universal argument prefix function. Here is the original function (as you can see 4 is hardcoded in the function):
(defun universal-argument ()
"Begin a numeric argument for the following command.
Digits or minus sign following \\[universal-argument] make up the numeric argument.
\\[universal-argument] following the digits or minus sign ends the argument.
\\[universal-argument] without digits or minus sign provides 4 as argument.
Repeating \\[universal-argument] without digits or minus sign
multiplies the argument by 4 each time.
For some commands, just \\[universal-argument] by itself serves as a flag
which is different in effect from any particular numeric argument.
These commands include \\[set-mark-command] and \\[start-kbd-macro]."
(interactive)
(setq prefix-arg (list 4))
(universal-argument--mode))
In your init file, you can create your own custom version of this, and bind it to C-u:
(defun my-universal-argument ()
(interactive)
(setq prefix-arg (list 10))
(universal-argument--mode))
(global-set-key (kbd "C-u") 'my-universal-argument)
However, see #Drew's comment below about why this might not be a great idea, and may have undesired/unexpected consequences.
Also, keep in mind that you can press C-u multiple times as a prefix argument to multiply the repetitions by 4. For example, using the original default of 4, C-u C-u C-n will move down 16 (4*4) lines, and so on.
I tried sometimes and realized that exporter can recognize $1100^{\circ}C$ and 1000^\circ, but can not recognize 1000^\circC and 1000^\circ C correctly, so which is the best way to add a ℃? I would not like to use $1100^{\circ}C$, because it need to add two whitespaces in both sides.
Why not use an appropriate wysiwyg character here.
A sample org file:
Foo! The temp is 12 °C.
The PDF after C-x C-e l o:
Different extended alphabet symbols can be typed with Emacs' C-x 8 subbindings. For instance:
Key Gives
---------------------
C-x 8 o °
C-x 8 u µ
Be sure to check C-x 8 C-h for some of the mapped symbols.
Check also the input method TeX. It is pretty cool. It translates directly written TeX macros into unicode symbols. C-\ TeX RET and you're set.
If i would insert a Celsius symbol with C-x 8 o , it still would convert it to a non printable or useless character. The only way the Celsius sign works for me is when i insert it in org-mode with \textdegree
Another possibility is to replace the symbol with some latex command. I would recommend the siunitx package which I think yields better results in general. For example, with the code below and \usepackage{siunitx} in the header, you could write 12 °C in the Org document and it becomes \SI{12}{\degreeCelsius} in the tex file.
(defun org-latex-replace-degree (text backend info)
(when (org-export-derived-backend-p backend 'latex)
(replace-regexp-in-string
"\\([0-9\.]*\\)\s?\\(°C\\)" "\\\\SI\{\\1\}\{\\\\degreeCelsius\}" text)))
(add-to-list 'org-export-filter-plain-text-functions 'org-latex-replace-degree)
I am writing a function which returns linguistic information about the character at point. This is easy for pre-composed characters. However, I wish to account for diacritics. I believe these are referred to as "marks" or "combining characters" in Unicode (cf. plane U+0300 - U+036F).
For example, to place the centralization diacritic (U+0306) on the character e:
e C-x 8 <RET> 0306 <RET>
Run C-u C-x = on the resulting character and you will see something like "Composed with the following character(s) ̆ "
Functions such as following-char unfortunately only return the base character, i.e. "e", and ignore any combining diacritics. Is there any way to get these?
EDIT: slitvinov pointed out that the resulting glyph consists of two characters. If you place point before the glyph created by the above code, and execute (point) before and after running forward-char, you will see point increase by 2. I figured I could hack a solution through this behaviour, but it appears that inside a progn statement (or function definition), forward-char only moves point forward by one... try it in a defun or with (progn (forward-char) (point)). Why might this be?
I think diacritic e is treated as two characters. I put this combination in the file
e(diacritic e)e.
ĕee
(char-after 1)
(char-after 2)
(char-after 3)
(char-after 4)
It gives me.
101 101 774 101
And 774 is a decimal form of 0306.
Imagine I've got the following in a text file opened under Emacs:
some 34
word 30
another 38
thing 59
to 39
say 10
here 47
and I want to turn into this, adding 1 to every number made of 2 digits:
some 35
word 31
another 39
thing 60
to 40
say 11
here 48
(this is a short example, my actual need is on a much bigger list, not my call)
How can I do this from Emacs?
I don't mind calling some external Perl/sed/whatever magic as long as the call is made directly from Emacs and operates only on the marked region I want.
How would you automate this from Emacs?
I think the answer I'm thinking of consist in calling shell-command-on-region and replace the region by the output... But I'm not sure as to how to concretely do this.
This can be solved by using the command query-replace-regexp (bound to C-M-%):
C-M-%
\b[0-9][0-9]\b
return
\,(1+ \#&)
The expression that follows \, would be evaluated as a Lisp expression, the result of which used as the replacement string. In the Lisp expression, \#& would be replaced by the matched string, interpreted as a number.
By default, this works on the whole document, starting from the cursor. To have this work on the region, there are several posibilities:
If transient-mark-mode is turned on, you just need to select the region normally (using point and mark);
If for some reason you don't like transient-mark-mode, you may use narrow-to-region to restrict the changes to a specific region: select a region using point and mark, C-x n n to narrow, perform query-replace-regexp as described above, and finally C-x n w to widen. (Thanks to Justin Smith for this hint.)
Use the mouse to select the region.
See section Regexp Replacement of the Emacs Manual for more details.
Emacs' column editing mode is what you need.
Activate it typing M-x cua-mode.
Go to the beginning of the rectangle (leave cursor on character 3) and press C-RET.
Go to the end of the rectangle (leave cursor on character 7). You will be operating on the highlighted region.
Now press M-i which increments all values in the region.
You're done.! remove dead ImageShack links
It doesn't protect against 99->100.
(defun add-1-to-2-digits (b e)
"add 1 to every 2 digit number in the region"
(interactive "r")
(goto-char b)
(while (re-search-forward "\\b[0-9][0-9]\\b" e t)
(replace-match (number-to-string (+ 1 (string-to-int (match-string 0)))))))
Oh, and it operates on the region. If you want the entire file, then you replace b and e with (point-min) and nil.
Moderately tested; use M-: and issue the following command:
(while (re-search-forward "\\<[0-9][0-9]\\>" nil t) (let ((x (match-string 0))) (delete-backward-char 2) (insert (format "%d" (1+ (string-to-int x))))))
I managed to get it working in a different way using the following (my awk-fu ain't strong so it probably can be done in a simpler way):
C-u M-x shell-command-on-region RET awk '$2>=0&&$2<=99 {$2++} {print}' RET
but I lost my indentation in the process : )
Seeing all these answers, I can't help but have a lot of respect for Emacs...