all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* clear-kill-ring function
@ 2015-10-27 18:24 Sharon Kimble
  0 siblings, 0 replies; 9+ messages in thread
From: Sharon Kimble @ 2015-10-27 18:24 UTC (permalink / raw)
  To: help-emacs

[-- Attachment #1: Type: text/plain, Size: 1306 bytes --]

For a long time I have wanted to have some way of clearing the
kill-ring, and I have recently started using the "cliphist" package,
like this -

--8<---------------cut here---------------start------------->8---
#+begin_src emacs-lisp
(require 'cliphist)
(global-set-key (kbd "s-,") 'cliphist-select-item)
(global-set-key (kbd "s-.") 'cliphist-paste-item)
#+end_src
--8<---------------cut here---------------end--------------->8---

which is working very well to use data from "parcellite".

And I seem to have found a way of clearing the kill-ring, at http://qdot.github.io/conf_emacs/

--8<---------------cut here---------------start------------->8---
#+begin_src emacs-lisp
(defun qdot/clear-kill-ring ()
  "Clear the kill ring variable"
  (setq kill-ring nil))
(global-set-key (kbd "s-/") 'qdot/clear-kill-ring)
#+end_src
--8<---------------cut here---------------end--------------->8---

However when I do "s-/" emacs replied with

╭────
│(wrong-type-argument commandp qdot/clear-kill-ring) in ad-Advice-call-interactively
╰────

So what should I have in my function please to get it working properly?

Thanks
Sharon.
-- 
A taste of linux = http://www.sharons.org.uk
TGmeds = http://www.tgmeds.org.uk
Debian 8.0, fluxbox 1.3.7, emacs 24.5.1

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

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

* Re: clear-kill-ring function
       [not found] <mailman.1159.1445970298.7904.help-gnu-emacs@gnu.org>
@ 2015-10-27 18:49 ` Barry Margolin
  2015-10-27 19:29   ` Sharon Kimble
  0 siblings, 1 reply; 9+ messages in thread
From: Barry Margolin @ 2015-10-27 18:49 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 938 bytes --]

In article <mailman.1159.1445970298.7904.help-gnu-emacs@gnu.org>,
 Sharon Kimble <boudiccas@skimble.plus.com> wrote:

> --8<---------------cut here---------------start------------->8---
> #+begin_src emacs-lisp
> (defun qdot/clear-kill-ring ()
>   "Clear the kill ring variable"
>   (setq kill-ring nil))
> (global-set-key (kbd "s-/") 'qdot/clear-kill-ring)
> #+end_src
> --8<---------------cut here---------------end--------------->8---
> 
> However when I do "s-/" emacs replied with
> 
> ¢~¢w¢w¢w¢w
> ¢x(wrong-type-argument commandp qdot/clear-kill-ring) in 
> ad-Advice-call-interactively
> ¢¢¢w¢w¢w¢w
> 
> So what should I have in my function please to get it working properly?

You forgot to put (interactive) in qdot/clear-kill-ring, to indicate 
that it's a command, not just an ordinary function.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


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

* Re: clear-kill-ring function
  2015-10-27 18:49 ` clear-kill-ring function Barry Margolin
@ 2015-10-27 19:29   ` Sharon Kimble
  2015-10-27 20:18     ` Michael Heerdegen
  2015-10-28  2:14     ` Emanuel Berg
  0 siblings, 2 replies; 9+ messages in thread
From: Sharon Kimble @ 2015-10-27 19:29 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1236 bytes --]

Barry Margolin <barmar@alum.mit.edu> writes:

> In article <mailman.1159.1445970298.7904.help-gnu-emacs@gnu.org>,
>  Sharon Kimble <boudiccas@skimble.plus.com> wrote:
>
>> --8<---------------cut here---------------start------------->8---
>> #+begin_src emacs-lisp
>> (defun qdot/clear-kill-ring ()
>>   "Clear the kill ring variable"
>>   (setq kill-ring nil))
>> (global-set-key (kbd "s-/") 'qdot/clear-kill-ring)
>> #+end_src
>> --8<---------------cut here---------------end--------------->8---
>> 
>> However when I do "s-/" emacs replied with
>> 
>> ¢~¢w¢w¢w¢w
>> ¢x(wrong-type-argument commandp qdot/clear-kill-ring) in 
>> ad-Advice-call-interactively
>> ¢¢¢w¢w¢w¢w
>> 
>> So what should I have in my function please to get it working properly?
>
> You forgot to put (interactive) in qdot/clear-kill-ring, to indicate 
> that it's a command, not just an ordinary function.

You mean like -

╭────
│(defun qdot/clear-kill-ring (interactive)
╰────

I'm not sure what you mean or how to show it. Is that what you meant?

Thanks
Sharon.
-- 
A taste of linux = http://www.sharons.org.uk
TGmeds = http://www.tgmeds.org.uk
Debian 8.0, fluxbox 1.3.7, emacs 24.5.1

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

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

* Re: clear-kill-ring function
  2015-10-27 19:29   ` Sharon Kimble
@ 2015-10-27 20:18     ` Michael Heerdegen
  2015-10-28  6:06       ` Sharon Kimble
       [not found]       ` <mailman.1186.1446012388.7904.help-gnu-emacs@gnu.org>
  2015-10-28  2:14     ` Emanuel Berg
  1 sibling, 2 replies; 9+ messages in thread
From: Michael Heerdegen @ 2015-10-27 20:18 UTC (permalink / raw)
  To: help-gnu-emacs

Sharon Kimble <boudiccas@skimble.plus.com> writes:

> You mean like -
>
> ╭────
> │(defun qdot/clear-kill-ring (interactive)
> ╰────

More like

  (defun qdot/clear-kill-ring ()
    (interactive)
    ...)

See (info "(elisp) Using Interactive").


Michael.




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

* Re: clear-kill-ring function
  2015-10-27 19:29   ` Sharon Kimble
  2015-10-27 20:18     ` Michael Heerdegen
@ 2015-10-28  2:14     ` Emanuel Berg
  1 sibling, 0 replies; 9+ messages in thread
From: Emanuel Berg @ 2015-10-28  2:14 UTC (permalink / raw)
  To: help-gnu-emacs

Sharon Kimble <boudiccas@skimble.plus.com> writes:

> (defun qdot/clear-kill-ring (interactive)
>
> I'm not sure what you mean or how to show it.
> Is that what you meant?

You put (interactive) after the parameter list (the
argument names), which is empty in your case so should
be the empty list, ().

An interactive function is a "command", which means
you can invoke it from M-x and also bind it to a key.

There are situations where you can have the same
function behave differently when called from Elisp
(i.e., invoked from another piece of code) compared to
when it is used interactively (again, with M-x or
a keystroke bound to that function) - however, as for
me, I don't see a great value in this distinction and
has only rarely used it. Perhaps someone who disagrees
will explain why it is there and what benefits
it brings.

Note that you can invoke non-interactive functions
with `eval-expr' (or `M-:') so it is not like they are
inaccessible to the "interactive" user. (They will
execute noninteractively still, of course.)

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: clear-kill-ring function
  2015-10-27 20:18     ` Michael Heerdegen
@ 2015-10-28  6:06       ` Sharon Kimble
       [not found]       ` <mailman.1186.1446012388.7904.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Sharon Kimble @ 2015-10-28  6:06 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1281 bytes --]

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Sharon Kimble <boudiccas@skimble.plus.com> writes:
>
>> You mean like -
>>
>> ╭────
>> │(defun qdot/clear-kill-ring (interactive)
>> ╰────
>
> More like
>
>   (defun qdot/clear-kill-ring ()
>     (interactive)
>     ...)
>
> See (info "(elisp) Using Interactive").

Thanks for this Michael, I now have -

--8<---------------cut here---------------start------------->8---
#+begin_src emacs-lisp
(defun clear-kill-ring ()
(interactive)
  "Clear the kill ring variable"
  (setq kill-ring nil))
(global-set-key (kbd "s-/") 'clear-kill-ring)
#+end_src
--8<---------------cut here---------------end--------------->8---

And have restarted emacs several times, but if I do a "s-." before hand
I can see several items on the kill-ring. So I then do "s-/" to clear
the kill-ring, and if I then do a further "s-." it shows that there
still remains the same items on the kill-ring, i.e. nothing has changed!
Or, IOW, the function isn't working!

So I'm back to my original question, what do I have to do to get it
working please?

Thanks
Sharon.
-- 
A taste of linux = http://www.sharons.org.uk
TGmeds = http://www.tgmeds.org.uk
Debian 8.0, fluxbox 1.3.7, emacs 24.5.1

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

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

* Re: clear-kill-ring function
       [not found]       ` <mailman.1186.1446012388.7904.help-gnu-emacs@gnu.org>
@ 2015-10-28 10:37         ` Joost Kremers
  2015-10-28 12:46           ` Michael Heerdegen
  2015-10-29  2:34           ` Emanuel Berg
  0 siblings, 2 replies; 9+ messages in thread
From: Joost Kremers @ 2015-10-28 10:37 UTC (permalink / raw)
  To: help-gnu-emacs

Sharon Kimble wrote:
>=2D-8<---------------cut here---------------start------------->8---
> #+begin_src emacs-lisp
> (defun clear-kill-ring ()
> (interactive)
>   "Clear the kill ring variable"
>   (setq kill-ring nil))
> (global-set-key (kbd "s-/") 'clear-kill-ring)
> #+end_src
>=2D-8<---------------cut here---------------end--------------->8---

Note that the doc string should go before the (interactive) call:

```
(defun clear-kill-ring ()
  "Clear the kill ring variable"
  (interactive)
  (setq kill-ring nil))
(global-set-key (kbd "s-/") 'clear-kill-ring)
```

> And have restarted emacs several times, but if I do a "s-." before hand
> I can see several items on the kill-ring. So I then do "s-/" to clear
> the kill-ring, and if I then do a further "s-." it shows that there
> still remains the same items on the kill-ring, i.e. nothing has changed!
> Or, IOW, the function isn't working!

It probably is. Assuming that you have `s-.` bound to
`cliphist-paste-item` as in your original post, hitting `s-.` will
(presumably; I don't know cliphist) populate the kill ring with the
items in the clipboard history. Emtpying the Emacs kill ring doesn't
change the clipboard history, because they're two different things.

To see the contents of the kill ring, you can evaluate the variable
`kill-ring` in the *scratch* buffer (put `kill-ring` on a separate line
and hit C-j). Or use `C-h v kill-ring RET`.

There's also the packge `browse-kill-ring`, which shows the contents of
the kill ring in a separate buffer and allows you to pick any item to
paste.

HTH

-- 
Joost Kremers                                   joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


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

* Re: clear-kill-ring function
  2015-10-28 10:37         ` Joost Kremers
@ 2015-10-28 12:46           ` Michael Heerdegen
  2015-10-29  2:34           ` Emanuel Berg
  1 sibling, 0 replies; 9+ messages in thread
From: Michael Heerdegen @ 2015-10-28 12:46 UTC (permalink / raw)
  To: help-gnu-emacs

Joost Kremers <joost.m.kremers@gmail.com> writes:

> (defun clear-kill-ring ()
>   "Clear the kill ring variable"
>   (interactive)
>   (setq kill-ring nil))
> (global-set-key (kbd "s-/") 'clear-kill-ring)

It's more consistent to also reset the yank pointer:

(defun clear-kill-ring ()
  "Clear the kill ring variable"
  (interactive)
  (setq kill-ring nil
        kill-ring-yank-pointer nil))

> > Or, IOW, the function isn't working!
>
> It probably is.

Indeed, it is.


Michael.




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

* Re: clear-kill-ring function
  2015-10-28 10:37         ` Joost Kremers
  2015-10-28 12:46           ` Michael Heerdegen
@ 2015-10-29  2:34           ` Emanuel Berg
  1 sibling, 0 replies; 9+ messages in thread
From: Emanuel Berg @ 2015-10-29  2:34 UTC (permalink / raw)
  To: help-gnu-emacs

Joost Kremers <joost.m.kremers@gmail.com> writes:

> Note that the doc string should go before the
> (interactive) call ...
>
>    "Clear the kill ring variable"

Docstrings should be either all user-oriented or all
technology ditto. Or both, in different paragraphs.

In general I'd say user-oriented is much better,
especially in the context of an Emacs help screen and
an interactive function, like what we have here.

However, despite being interactive, this function is
all about technology which might motivate some
tech material.

So either

    "Discard all killed text."

or

    "Set `kill-ring' and `kill-ring-yank-pointer'
    to nil."

Or both:

    "Discard all killed text.\n\nI.e., set `kill-ring' and `kill-ring-yank-pointer' to nil."

As for "Clear the kill ring variable":

    1. It only explains what happens in terms of
       technology, not why anyone would do that or
       what is gained from a user perspective by doing
       it. (Here, there purpose is unclear - why would
       anyone do this? - perhaps the OP can explain
       the gain of having an interactive function
       do this.)

    2. There are many "kill ring" variables:

           kill-ring
           kill-ring-max
           kill-ring-yank-pointer

       Which one exactly? And if there is a mention of
       a variable, why not give the exact name and put
       it within `whatever' to make it hyperlinked?

    3. `kill-ring-max' is an integer, while
       `kill-ring' and `kill-ring-yank-pointer' are or
       leads to complicated data structures.
       What exactly does "clear" mean? 0, nil, or an
       empty data structure?

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

end of thread, other threads:[~2015-10-29  2:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1159.1445970298.7904.help-gnu-emacs@gnu.org>
2015-10-27 18:49 ` clear-kill-ring function Barry Margolin
2015-10-27 19:29   ` Sharon Kimble
2015-10-27 20:18     ` Michael Heerdegen
2015-10-28  6:06       ` Sharon Kimble
     [not found]       ` <mailman.1186.1446012388.7904.help-gnu-emacs@gnu.org>
2015-10-28 10:37         ` Joost Kremers
2015-10-28 12:46           ` Michael Heerdegen
2015-10-29  2:34           ` Emanuel Berg
2015-10-28  2:14     ` Emanuel Berg
2015-10-27 18:24 Sharon Kimble

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.