unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* copy-region-as-kill => variable
@ 2006-01-16 23:09 Tim Johnson
  0 siblings, 0 replies; 4+ messages in thread
From: Tim Johnson @ 2006-01-16 23:09 UTC (permalink / raw)


Hello:
  Is there a function that would operate as copy-region-as-kill,
but instead of copying to kill-ring would copy the data to a variable,
such as one created by 'defvar?
thanks
tim

-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: copy-region-as-kill => variable
       [not found] <mailman.1361.1137452959.26925.help-gnu-emacs@gnu.org>
@ 2006-01-16 23:59 ` Harald Hanche-Olsen
  2006-01-17  1:08   ` Tim Johnson
       [not found]   ` <mailman.1370.1137460102.26925.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Harald Hanche-Olsen @ 2006-01-16 23:59 UTC (permalink / raw)


+ Tim Johnson <tim@johnsons-web.com>:

|   Is there a function that would operate as copy-region-as-kill,
| but instead of copying to kill-ring would copy the data to a variable,
| such as one created by 'defvar?

Such a beast is not terribly hard to write:

(defun copy-region-to-variable (start end variable)
  (interactive "r\nvCopy region to variable: ")
  (set variable (buffer-substring start end)))

Note that this copies text properties as well.
You may find this confusing.  Or perhaps not.

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- Debating gives most of us much more psychological satisfaction
  than thinking does: but it deprives us of whatever chance there is
  of getting closer to the truth.  -- C.P. Snow

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: copy-region-as-kill => variable
  2006-01-16 23:59 ` Harald Hanche-Olsen
@ 2006-01-17  1:08   ` Tim Johnson
       [not found]   ` <mailman.1370.1137460102.26925.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Tim Johnson @ 2006-01-17  1:08 UTC (permalink / raw)


* Harald Hanche-Olsen <hanche@math.ntnu.no> [060116 15:08]:
> + Tim Johnson <tim@johnsons-web.com>:
> 
> |   Is there a function that would operate as copy-region-as-kill,
> | but instead of copying to kill-ring would copy the data to a variable,
> | such as one created by 'defvar?
> 
> Such a beast is not terribly hard to write:
> 
> (defun copy-region-to-variable (start end variable)
>   (interactive "r\nvCopy region to variable: ")
>   (set variable (buffer-substring start end)))
> 
> Note that this copies text properties as well.
> You may find this confusing.  Or perhaps not.
Hi Harald:

(defun copy-rad-tag-text ()
  "Copy text inside of radio pseudo-tag to custom variable"
  (interactive)
  (let ((endpoint (point)))
    (message (number-to-string endpoint))
    (search-backward "rbtn")
    (forward-char 5)
    (setq tj-adhoc-1 (buffer-substring (point) endpoint))))
;; I get a wrong-type-of-argument error with 'set, thus setq.

Thanks for getting me started with this 'buffer-substring was the
key.

Cheers
-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: copy-region-as-kill => variable
       [not found]   ` <mailman.1370.1137460102.26925.help-gnu-emacs@gnu.org>
@ 2006-01-17  1:46     ` Harald Hanche-Olsen
  0 siblings, 0 replies; 4+ messages in thread
From: Harald Hanche-Olsen @ 2006-01-17  1:46 UTC (permalink / raw)


+ Tim Johnson <tim@johnsons-web.com>:

| (defun copy-rad-tag-text ()
|   "Copy text inside of radio pseudo-tag to custom variable"

I should have guessed you had a more specialized itch scratch than you
were letting on.  8-)

| ;; I get a wrong-type-of-argument error with 'set, thus setq.

Yeah, set does an extra indirection, since it is an ordinary function:
Its first variable is evaluated - the value must be a symbol - and
then the value is assigned to that symbol.

So after, e.g.,

(let ((foo 'bar)) (set foo "Foo!"))

then bar has the value "Foo!"
It worked in my general function, but not in your specialized one.
Usually it's setq you want - set is for special occasions.

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- Debating gives most of us much more psychological satisfaction
  than thinking does: but it deprives us of whatever chance there is
  of getting closer to the truth.  -- C.P. Snow

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-01-17  1:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-16 23:09 copy-region-as-kill => variable Tim Johnson
     [not found] <mailman.1361.1137452959.26925.help-gnu-emacs@gnu.org>
2006-01-16 23:59 ` Harald Hanche-Olsen
2006-01-17  1:08   ` Tim Johnson
     [not found]   ` <mailman.1370.1137460102.26925.help-gnu-emacs@gnu.org>
2006-01-17  1:46     ` Harald Hanche-Olsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).