‘The half minute which we daily devote to the winding-up of our watches is an exertion of labour almost insensible; yet, by the aid of a few wheels, its effect is spread over the whole twenty-four hours.’

Grab word etymologies in Emacs

Benjamin Slade

On Xah Lee’s blog I noticed an entry on linking to word etymologies from Emacs (2018-08-16: “emacs, create link of word etymology”). What his function does is create a html link to the Etymonline.com page on the currently selected word.

But I thought: it would be great to have a quick way of pulling up etymological information within Emacs itself. So, with a little help from Links (i.e. you’ll need to have Links installed), here is a first attempt at such a function:

(defun slade/etymonbuf ()
  "Look up word etymology notes from http://www.etymonline.com. Requires [[http://links.twibright.com/][links] to be installed."
  (let ($p1 $p2 $input $result)    ;; lifted from Xah Lee's 2018-08-16: "emacs, create link of word etymology"
    (if (use-region-p)
	(progn (setq $p1 (region-beginning))
	       (setq $p2 (region-end)))
      (progn (setq $p1 (line-beginning-position))
	     (setq $p2 (line-end-position))))
    (setq $input (buffer-substring-no-properties $p1 $p2)) ;;
    (generate-new-buffer $input)  ; generate new buffer titled with entry word
    (switch-to-buffer (last-buffer)) ; switch to that new buffer
    (insert (shell-command-to-string (concat "links -dump http://www.etymonline.com/word/" $input))) ; dump text via links from etymonline
    (goto-char (point-min)) ; go to beginning
    (if (re-search-forward "Error 404 (Not Found)" nil t)   ; for non-word or words with no etymonline entry
	(slade/word-not-found)   ; if 404, kill buffer and display minibuffer message
      (slade/trim-etymonbuf))))  ; otherwise trim off unneeded text from header and footer

(defun slade/trim-etymonbuf ()
  "Trim off unneeded text from top and bottom."
  (goto-char (point-min))		; goto beginning of buffer
  (search-forward "[\s\s]") 		; the text output of links always delivers text with a "[  ]" right before the text we want
  (let ((begdel (point)))
    (delete-region 1 begdel))		; delete from beginning of buffer until "[  ]"
  (goto-char (point-max))  		; goto end of buffer
  (search-backward-regexp "Share[[:space:]]*Share on FacebookShare")   ; the unneeded text at the bottom starts with a "Share" section
  (let ((enddel (point)))
    (delete-region (point-max) enddel))	; delete from end of buffer until Share section
  (goto-char (point-min)))		; move point back to beginning

(defun slade/word-not-found ()
  "Delete buffer and display minibuffer message."
  (message "Sorry, word not found."))

After eval'ing the above, one day, if you have an idle fancy to know the etymology of a word, you can select it and call slade/etymonbuf and have a quick peek at what Etymonline has to say. Here’s what you get if you try this on “lisp”:

                                lisp (n.)

"act or habit of lisping," 1620s, from lisp (v.).

lisp (v.)

sometimes lipse, late 14c. alteration of wlisp, from late Old English
awlyspian "to lisp, to pronounce 's' and 'z' imperfectly," from wlisp
(adj.) "lisping," which is probably imitative (compare Middle Dutch, Old
High German lispen, Danish læspe, Swedish läspa). General sense "speak
imperfectly or childishly" is from 17c. Transitive sense from 1610s.
Related: Lisped; lisping. Suggestive of effeminacy from 14c.

Probably not the lisp you were looking for, but interesting none the less.

Of course it would be nice to retain italics and not to have to depend on an external application, so there’s more that can be done.

If you have written a response to this, enter your response post's URL below.

Or, you can send a "comment" webmention (it's OK if you don't know what that means). When asked about your website on an IndieAuth login screen, simply type https://commentpara.de.

Markdown Support**bold**, _italics_, ~~strikethrough~~, [descr](link), `monospace`, ```LANG\nline1\nline2\n``` (Yep, multi-line code blocks too, with syntax highlighting!), auto-hyperlinking.

Webmentions #

Comment by Anonymous on Sun Mar 21, 2021 20:03 UTC
Interesting function. But, I think there are better etymology sites. Perhaps wiki-dictionary or even others I do not know… Also. Try to put this as a package in MELPA. So that other can help your code. Keeps updated. Anyways…
Comment by Benjamin Slade on Tue Aug 28, 2018 23:34 UTC
@Kaushal Modi: Thanks! Part of what I would like to be able to do is preserve the italics, but it seems that etymonline doesn’t use plain tags for this, but some sort of custom-defined “foreign” tagging. Anyway, I’m not sure how I could extract that info from eww.
Comment by Kaushal Modi on Mon Aug 27, 2018 12:11 UTC

Thanks for sharing this. I’ll try this out later today.

Also, you might be able to just use the internal eww browser than depending on the external application links.

If interested, you can see how I use eww to fetch the link of the very first Google result.. the modi/eww-get-link function in my setup-eww.