help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Copy whitespace-delimited text to variable


From: Emanuel Berg
Subject: Re: Copy whitespace-delimited text to variable
Date: Thu, 08 Mar 2018 07:10:26 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Tim Johnson wrote:

> Example: in elpy
> g.args (where cursor is at or following 's')
> (current-word) would just return 'args', I need 'g.args'
> and I don't wish to modify the syntax table.
>
> Before I roll my own, I'd rather not
> re-invent the wheel...

Why not? To quote the barrel racer, just try -
and you will fly :)

(defun previous-word ()
  (interactive)
  (save-excursion
    (let((word-stop (progn (backward-word 1)
                           (forward-word  1)
                           (point) ))
         (word-start (re-search-backward "[[:space:]]" (point-min) t)) )
      (when word-start
        (message
         (string-trim
          (buffer-substring-no-properties word-start word-stop) ))))))

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]