1

I was wondering how I can store certain text in a given register using elisp (so that I can set in a configuration files).

I know that I can do this manually with C-x r s r to store some text into the register r. Then, I can use it by C-x r i r.

I tried to set the register as follows:

(set-register 'r' "hI")

, and in the Help window I see that

register-alist’s value is ((r . "hI"))

But, when trying to use it with C-x r i r, I get:

user-error: Register does not contain text

I don't know much elisp.

Could someone explain how to set the content of the register in elisp correctly?

Drew
  • 77,472
  • 10
  • 114
  • 243
tinlyx
  • 1,342
  • 1
  • 13
  • 27
  • (set-register ?r "hI") – Tyler Sep 13 '22 at 00:19
  • @Tyler Thanks! The linked question does not answer mine. I wanted something more specific, and nothing about interactive there. The answer there actually triggered this question. I saw mention of set-register there, but couldn't figure out how to use it (due to my lack of knowledge on elisp). Hence this question. – tinlyx Sep 13 '22 at 00:48
  • ?r is how Emacs Lisp represents the literal character r in lisp programs. The point that @Tyler is making is that the name of a register is a single character, not a string or a symbol or anything more complicated. So (set-register ?r "hI") sets the register named r to have the string hI as its contents. – NickD Sep 13 '22 at 01:15
  • @NickD Thanks. That's where I got it wrong. I thought it's single-quotes vs double quotes as in C/C++. – tinlyx Sep 13 '22 at 01:19
  • The linked question is a bit different, but the answer includes the distinction between strings ("r") and characters (?r) with respect to register names, which is the bit you were missing – Tyler Sep 13 '22 at 01:51
  • https://emacs.stackexchange.com/tags/elisp/info – Drew Sep 13 '22 at 03:55
  • Right - sIngle quotes are used for quoting in Emacs Lisp (i.e. to protect something from being evaluated)- they are never used as delimiters. – NickD Sep 13 '22 at 12:45

0 Answers0