all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Filename of buffer into kill-ring functionality
@ 2006-08-31 10:04 Marco Wahl
  2006-08-31 12:40 ` Reiner Steib
  2006-09-01  8:58 ` Eli Zaretskii
  0 siblings, 2 replies; 7+ messages in thread
From: Marco Wahl @ 2006-08-31 10:04 UTC (permalink / raw)


Hello,

is there already a function in emacs that puts the
absolute filename belonging to a buffer into the
kill-ring?  Or is there even a keyboard-shortcut?


TIA
-- 
Marco Wahl
http://visenso.com

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

* Re: Filename of buffer into kill-ring functionality
  2006-08-31 10:04 Filename of buffer into kill-ring functionality Marco Wahl
@ 2006-08-31 12:40 ` Reiner Steib
  2006-08-31 15:43   ` Kevin Rodgers
       [not found]   ` <mailman.6092.1157039301.9609.help-gnu-emacs@gnu.org>
  2006-09-01  8:58 ` Eli Zaretskii
  1 sibling, 2 replies; 7+ messages in thread
From: Reiner Steib @ 2006-08-31 12:40 UTC (permalink / raw)


On Thu, Aug 31 2006, Marco Wahl wrote:

> is there already a function in emacs that puts the
> absolute filename belonging to a buffer into the
> kill-ring?  

I'm not aware of any predefined function for this.  You might use this
one:

(defun rs-kill-ring-save-buffer-file-name ()
  "Add `buffer-file-name' in the kill ring."
  (interactive)
  (if (not (stringp buffer-file-name))
      (error "Not visiting a file.")
    (kill-new buffer-file-name)
    ;; Give some visual feedback:
    (message "String \"%s\" saved to kill ring." buffer-file-name)
    buffer-file-name))

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

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

* Re: Filename of buffer into kill-ring functionality
  2006-08-31 12:40 ` Reiner Steib
@ 2006-08-31 15:43   ` Kevin Rodgers
  2006-08-31 19:08     ` Reiner Steib
       [not found]   ` <mailman.6092.1157039301.9609.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 7+ messages in thread
From: Kevin Rodgers @ 2006-08-31 15:43 UTC (permalink / raw)


Reiner Steib wrote:
> On Thu, Aug 31 2006, Marco Wahl wrote:
> 
>> is there already a function in emacs that puts the
>> absolute filename belonging to a buffer into the
>> kill-ring?  
> 
> I'm not aware of any predefined function for this.  You might use this
> one:
> 
> (defun rs-kill-ring-save-buffer-file-name ()
>   "Add `buffer-file-name' in the kill ring."
>   (interactive)
>   (if (not (stringp buffer-file-name))
>       (error "Not visiting a file.")
>     (kill-new buffer-file-name)
>     ;; Give some visual feedback:
>     (message "String \"%s\" saved to kill ring." buffer-file-name)
>     buffer-file-name))

That can be easily generalized:

(defun kill-new-string-variable (variable)
   "Make the string value of VARIABLE the latest kill in the kill ring."
   (interactive (let ((current-buffer (current-buffer)))
		 (intern (completing-read "Variable: " obarray
					  (lambda (symbol)
					    (with-current-buffer current-buffer
					      (and (boundp symbol)
						   (stringp
						    (symbol-value symbol)))))
					  t))))
   ;; Let symbol-value and kill-new signal errors for unbound variables
   ;; and non-string values, respectively:
   (kill-new (symbol-value variable)))

(defun kill-new-buffer-file-name ()
   (kill-new-string-variable 'buffer-file-name))

-- 
Kevin

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

* Re: Filename of buffer into kill-ring functionality
  2006-08-31 15:43   ` Kevin Rodgers
@ 2006-08-31 19:08     ` Reiner Steib
  2006-08-31 20:40       ` Kevin Rodgers
  0 siblings, 1 reply; 7+ messages in thread
From: Reiner Steib @ 2006-08-31 19:08 UTC (permalink / raw)


On Thu, Aug 31 2006, Kevin Rodgers wrote:

> (defun kill-new-string-variable (variable)
>   "Make the string value of VARIABLE the latest kill in the kill ring."
>   (interactive (let ((current-buffer (current-buffer)))
> 		 (intern (completing-read "Variable: " obarray
> 					  (lambda (symbol)
> 					    (with-current-buffer current-buffer
> 					      (and (boundp symbol)
> 						   (stringp
> 						    (symbol-value symbol)))))

Is there a reason why you use (boundp symbol) inside
(with-current-buffer ...)?  In other words: Is there any difference
between these variants?

(with-current-buffer current-buffer
  (and (boundp symbol)
       (stringp	(symbol-value symbol))))

(and (boundp symbol)
     (with-current-buffer current-buffer
       (stringp (symbol-value symbol))))

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

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

* Re: Filename of buffer into kill-ring functionality
  2006-08-31 19:08     ` Reiner Steib
@ 2006-08-31 20:40       ` Kevin Rodgers
  0 siblings, 0 replies; 7+ messages in thread
From: Kevin Rodgers @ 2006-08-31 20:40 UTC (permalink / raw)


Reiner Steib wrote:
> On Thu, Aug 31 2006, Kevin Rodgers wrote:
> 
>> (defun kill-new-string-variable (variable)
>>   "Make the string value of VARIABLE the latest kill in the kill ring."
>>   (interactive (let ((current-buffer (current-buffer)))
>> 		 (intern (completing-read "Variable: " obarray
>> 					  (lambda (symbol)
>> 					    (with-current-buffer current-buffer
>> 					      (and (boundp symbol)
>> 						   (stringp
>> 						    (symbol-value symbol)))))
> 
> Is there a reason why you use (boundp symbol) inside
> (with-current-buffer ...)?  In other words: Is there any difference
> between these variants?
> 
> (with-current-buffer current-buffer
>   (and (boundp symbol)
>        (stringp	(symbol-value symbol))))
> 
> (and (boundp symbol)
>      (with-current-buffer current-buffer
>        (stringp (symbol-value symbol))))

The reason with-current-buffer is necessary at all is that the predicate
is run by completing-read with the minibuffer as the current buffer.  I
did it the first way when I first realized that, and it was simpler to
just wrap the entire body of the predicate.

Whether there's a difference between the two depends on whether a
variable with a buffer local value can be unbound globally (or in other
buffers, like the minibuffer).  I think that depends on how buffer local
bindings are implemented, and the first way is safer since it doesn't
depend on how that.

-- 
Kevin

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

* Re: Filename of buffer into kill-ring functionality
       [not found]   ` <mailman.6092.1157039301.9609.help-gnu-emacs@gnu.org>
@ 2006-09-01  7:38     ` Marco Wahl
  0 siblings, 0 replies; 7+ messages in thread
From: Marco Wahl @ 2006-09-01  7:38 UTC (permalink / raw)


Kevin Rodgers <ihs_4664@yahoo.com> writes:
> [...]
> (defun kill-new-string-variable (variable)
>    "Make the string value of VARIABLE the latest kill in the kill ring."
>    (interactive (let ((current-buffer (current-buffer)))
> 		 (intern (completing-read "Variable: " obarray
> 					  (lambda (symbol)
> 					    (with-current-buffer current-buffer
> 					      (and (boundp symbol)
> 						   (stringp
> 						    (symbol-value symbol)))))
> 					  t))))
>    ;; Let symbol-value and kill-new signal errors for unbound variables
>    ;; and non-string values, respectively:
>    (kill-new (symbol-value variable)))
> 
> (defun kill-new-buffer-file-name ()
>    (kill-new-string-variable 'buffer-file-name))

Thank you all!

Just a micro-remark for the not so lisp-experienced
user.  To be able to key-bind the latter function add
of '(interaction)' is needed:

(defun kill-new-buffer-file-name ()
  (interactive)
  (kill-new-string-variable 'buffer-file-name))


Best regards
-- 
Marco Wahl
http://visenso.com

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

* Re: Filename of buffer into kill-ring functionality
  2006-08-31 10:04 Filename of buffer into kill-ring functionality Marco Wahl
  2006-08-31 12:40 ` Reiner Steib
@ 2006-09-01  8:58 ` Eli Zaretskii
  1 sibling, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2006-09-01  8:58 UTC (permalink / raw)


> From: Marco Wahl <mw@visenso.de>
> Date: 31 Aug 2006 12:04:20 +0200
> 
> is there already a function in emacs that puts the
> absolute filename belonging to a buffer into the
> kill-ring?  Or is there even a keyboard-shortcut?

I use this trick:

   C-x C-f M-n C-a M-> M-w

You can create a keyboard macro from these, if you need to use it
frequently.

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

end of thread, other threads:[~2006-09-01  8:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-31 10:04 Filename of buffer into kill-ring functionality Marco Wahl
2006-08-31 12:40 ` Reiner Steib
2006-08-31 15:43   ` Kevin Rodgers
2006-08-31 19:08     ` Reiner Steib
2006-08-31 20:40       ` Kevin Rodgers
     [not found]   ` <mailman.6092.1157039301.9609.help-gnu-emacs@gnu.org>
2006-09-01  7:38     ` Marco Wahl
2006-09-01  8:58 ` Eli Zaretskii

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.