If you've ever written an Emacs function only to find out that it was there all along, masquerading as something else, this post is for you.
I just finished writing an Emacs function that copies the link at
point to the kill ring in EWW. It will remain unpublished. Why?
Because I discovered that shr-maybe-probe-and-copy-url
(bound to u and w
in eww-mode) does the same thing. Just position point
on a link and invoke it.
It's not obvious that pressing w will do this. In
fact the major mode help for eww-mode suggests
that w will not copy the link because it's
bound to eww-copy-page-url. But it turns out that if
point is on a link, w will
invoke shr-maybe-probe-and-copy-url, "which copies this
link's URL to the kill ring." The manual goes on to say, "If point is not
on a link, pressing w
calls eww-copy-page-url, which will copy the current
page's URL to the kill ring instead."1
Before writing my function I had been looking through the mode help
(C-h m from within a EWW buffer) and the EWW source code for any
function that looked like copy-link-at-point.
So how did I find out about this? I wanted to ensure that I was following the standard for capitalizing EWW, so I searched the web. This took me to the GNU Emacs manual, which has a section on EWW and shows it in all caps. But then my distractibility encouraged me to read a great deal more.
I've known that keybindings can change depending on the major mode.
But it seems a keybinding can change based on context
(i.e. the position of point). This idea is new to me. Maybe it's
common for a function to "hand off" to another based on context.
But in this case it seems irresponsible to omit documentation for
the alternate behavior of a w key press. Suppose a
user expects to copy the page URL and gets the URL of a link, instead?
While this was a frustrating experience, it is yet another reminder to RTFM. WDYT?
1 GNU Emacs EWW Basic Usage
No comments:
Post a Comment
Thank you for taking time to comment. Please note that comments may be deleted if they:
* Contain link(s) to a domain outside USA or Canada or to a commercial enterprise.
* Include non-English words or characters.
* Are irrelevant to the subject matter of the post.
For posts older than 14 days, comments are moderated and require approval.