* about register
@ 2007-04-21 13:19 Le TeXnicien de Surface
2007-04-21 15:37 ` Daniel Jensen
0 siblings, 1 reply; 5+ messages in thread
From: Le TeXnicien de Surface @ 2007-04-21 13:19 UTC (permalink / raw)
To: help-gnu-emacs
hello
I'd like to use the following command:
(defun complete-pid ()
(interactive)
(goto-char 0)
(number-to-register 1 "A")
(while (re-search-forward "p=PID=0" nil t)
(insert-register "A")
(increment-register 1 "A")
))
but when emacs finds the first `p=PID=' it says:
`register does not contain a number'
and stops.
it did work yesterday and I've not changed anything since (perhaps I did
something before using the command but I can't remember what)
Any hint appreciated
thanks for your reading so far
--
Le TeXnicien de Surface
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: about register
2007-04-21 13:19 about register Le TeXnicien de Surface
@ 2007-04-21 15:37 ` Daniel Jensen
2007-04-21 19:02 ` Le TeXnicien de Surface
0 siblings, 1 reply; 5+ messages in thread
From: Daniel Jensen @ 2007-04-21 15:37 UTC (permalink / raw)
To: help-gnu-emacs
Le TeXnicien de Surface <texnicien.de.surface@chezmoi.eur> writes:
> I'd like to use the following command:
> (defun complete-pid ()
> (interactive)
> (goto-char 0)
> (number-to-register 1 "A")
> (while (re-search-forward "p=PID=0" nil t)
> (insert-register "A")
> (increment-register 1 "A")
> ))
>
> but when emacs finds the first `p=PID=' it says:
> `register does not contain a number'
> and stops.
You are using strings as register names, this is why it does not work.
The problem lies in how registers are implemented; they are compared
behind the scenes with the eq predicate. However, strings are not eq.
Use characters instead (e.g., ?A), or perhaps better do away with the
register and use a variable.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: about register
2007-04-21 15:37 ` Daniel Jensen
@ 2007-04-21 19:02 ` Le TeXnicien de Surface
2007-04-22 10:42 ` Daniel Jensen
0 siblings, 1 reply; 5+ messages in thread
From: Le TeXnicien de Surface @ 2007-04-21 19:02 UTC (permalink / raw)
To: help-gnu-emacs
Daniel Jensen écrivait/wrote :
> Le TeXnicien de Surface <texnicien.de.surface@chezmoi.eur> writes:
>
>> I'd like to use the following command:
>> (defun complete-pid ()
>> (interactive)
>> (goto-char 0)
>> (number-to-register 1 "A")
>> (while (re-search-forward "p=PID=0" nil t)
>> (insert-register "A")
>> (increment-register 1 "A")
>> ))
>>
>> but when emacs finds the first `p=PID=' it says:
>> `register does not contain a number'
>> and stops.
>
> You are using strings as register names, this is why it does not work.
> The problem lies in how registers are implemented; they are compared
> behind the scenes with the eq predicate. However, strings are not eq.
> Use characters instead (e.g., ?A),
Thank you, it works.
BTW where could I find such a piece of information about character?
Is it lisp or emacs-specific?
> or perhaps better do away with the register and use a variable.
I will try to remember that next time I need such a command ;-) But won't
there be some catch to write the value of the variable in the buffer?
Once again, many thanks.
--
Le TeXnicien de Surface
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: about register
2007-04-21 19:02 ` Le TeXnicien de Surface
@ 2007-04-22 10:42 ` Daniel Jensen
2007-04-22 19:57 ` Le TeXnicien de Surface
0 siblings, 1 reply; 5+ messages in thread
From: Daniel Jensen @ 2007-04-22 10:42 UTC (permalink / raw)
To: help-gnu-emacs
Le TeXnicien de Surface <texnicien.de.surface@chezmoi.eur> writes:
> Daniel Jensen écrivait/wrote :
>
>> You are using strings as register names, this is why it does not work.
>> The problem lies in how registers are implemented; they are compared
>> behind the scenes with the eq predicate. However, strings are not eq.
>> Use characters instead (e.g., ?A),
>
> Thank you, it works.
> BTW where could I find such a piece of information about character?
> Is it lisp or emacs-specific?
You can start with reading the function documentation; `C-h f
number-to-register RET' and so on. That has always the most useful
information on how to use functions. In this case, it mentions that
characters are used to name registers.
To find answers to the more general questions, like "But, what is a
character anyway?", consult the Emacs Lisp manual. Chapter 2 describes
the data types and how you can use them in your programs. Here you will
find that characters can be entered with the question mark syntax in
Lisp code. The Lisp manual also holds information such as how registers
are implemented, but you don't need to know that just to use them.
>> or perhaps better do away with the register and use a variable.
>
> I will try to remember that next time I need such a command ;-) But won't
> there be some catch to write the value of the variable in the buffer?
It will require extra work to insert a number from a variable -- you
have to convert it to a string. But I think your code will be clearer if
you use a variable. You can do it like this:
(let ((counter 1))
(while ...
(insert (number-to-string counter))
(setq counter (+ counter 1))))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: about register
2007-04-22 10:42 ` Daniel Jensen
@ 2007-04-22 19:57 ` Le TeXnicien de Surface
0 siblings, 0 replies; 5+ messages in thread
From: Le TeXnicien de Surface @ 2007-04-22 19:57 UTC (permalink / raw)
To: help-gnu-emacs
Daniel Jensen écrivait/wrote :
> Le TeXnicien de Surface <texnicien.de.surface@chezmoi.eur> writes:
>
>> Daniel Jensen écrivait/wrote :
>>
>>> You are using strings as register names, this is why it does not work.
>>> The problem lies in how registers are implemented; they are compared
>>> behind the scenes with the eq predicate. However, strings are not eq.
>>> Use characters instead (e.g., ?A),
>>
>> Thank you, it works.
>> BTW where could I find such a piece of information about character?
>> Is it lisp or emacs-specific?
>
> You can start with reading the function documentation; `C-h f
> number-to-register RET' and so on. That has always the most useful
> information on how to use functions. In this case, it mentions that
> characters are used to name registers.
I did that but never thought there would be a difference between a char and
a string of one char (bad perl habit I guess :)
>
> To find answers to the more general questions, like "But, what is a
> character anyway?", consult the Emacs Lisp manual. Chapter 2 describes
> the data types and how you can use them in your programs. Here you will
> find that characters can be entered with the question mark syntax in
> Lisp code. The Lisp manual also holds information such as how registers
> are implemented, but you don't need to know that just to use them.
I read it some years ago but with big troubles in my private life and a year
without any linux box, I may have forgotten more than I ever learned.
>>> or perhaps better do away with the register and use a variable.
>>
>> I will try to remember that next time I need such a command ;-) But won't
>> there be some catch to write the value of the variable in the buffer?
>
> It will require extra work to insert a number from a variable -- you
> have to convert it to a string. But I think your code will be clearer if
> you use a variable. You can do it like this:
>
> (let ((counter 1))
> (while ...
> (insert (number-to-string counter))
> (setq counter (+ counter 1))))
May thanks again. I thought to remember something on the line of
`num-to-str' but I had not begun my investigations so far. It will save me
some hours.
--
Le TeXnicien de Surface
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-04-22 19:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-21 13:19 about register Le TeXnicien de Surface
2007-04-21 15:37 ` Daniel Jensen
2007-04-21 19:02 ` Le TeXnicien de Surface
2007-04-22 10:42 ` Daniel Jensen
2007-04-22 19:57 ` Le TeXnicien de Surface
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.