all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Copy whitespace-delimited text to variable
@ 2018-03-07 22:40 Tim Johnson
  0 siblings, 0 replies; 9+ messages in thread
From: Tim Johnson @ 2018-03-07 22:40 UTC (permalink / raw)
  To: Emacs

GNU Emacs 25.1. on ubuntu 14.04

Is there an elisp function which would return the whitespace
delimited text preceding the cursor?

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...
thanks
-- 
Tim 
http://www.akwebsoft.com, http://www.tj49.com



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

* Re: Copy whitespace-delimited text to variable
       [not found] <mailman.10256.1520462425.27995.help-gnu-emacs@gnu.org>
@ 2018-03-08  6:10 ` Emanuel Berg
  2018-03-08  6:37   ` Emanuel Berg
                     ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Emanuel Berg @ 2018-03-08  6:10 UTC (permalink / raw)
  To: help-gnu-emacs

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


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

* Re: Copy whitespace-delimited text to variable
  2018-03-08  6:10 ` Copy whitespace-delimited text to variable Emanuel Berg
@ 2018-03-08  6:37   ` Emanuel Berg
  2018-03-08 16:15   ` Tim Johnson
       [not found]   ` <mailman.10281.1520525754.27995.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 9+ messages in thread
From: Emanuel Berg @ 2018-03-08  6:37 UTC (permalink / raw)
  To: help-gnu-emacs

Before you try and fly, for `string-trim', do
(require 'subr-x) first.

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


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

* Re: Copy whitespace-delimited text to variable
  2018-03-08  6:10 ` Copy whitespace-delimited text to variable Emanuel Berg
  2018-03-08  6:37   ` Emanuel Berg
@ 2018-03-08 16:15   ` Tim Johnson
       [not found]   ` <mailman.10281.1520525754.27995.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 9+ messages in thread
From: Tim Johnson @ 2018-03-08 16:15 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg <moasen@zoho.com> [180307 21:27]:
> 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) ))))))
  :) I'm ready to fly ... and have already been using subr-x
  thanks, Emanuel
-- 
Tim 
http://www.akwebsoft.com, http://www.tj49.com



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

* Re: Copy whitespace-delimited text to variable
       [not found]   ` <mailman.10281.1520525754.27995.help-gnu-emacs@gnu.org>
@ 2018-03-09  6:47     ` Emanuel Berg
  2018-03-09 16:20       ` Tim Johnson
       [not found]       ` <mailman.10333.1520612428.27995.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 9+ messages in thread
From: Emanuel Berg @ 2018-03-09  6:47 UTC (permalink / raw)
  To: help-gnu-emacs

Tim Johnson wrote:

> :) I'm ready to fly ... and have already been
> using subr-x thanks, Emanuel

That was a fun piece of code to write, but in
all honesty your own suggestion of modifying
the syntax table is much better, especially if
you can do it temporarily so it is used
transparently and won't affect anything else.

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


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

* Re: Copy whitespace-delimited text to variable
  2018-03-09  6:47     ` Emanuel Berg
@ 2018-03-09 16:20       ` Tim Johnson
       [not found]       ` <mailman.10333.1520612428.27995.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Tim Johnson @ 2018-03-09 16:20 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg <moasen@zoho.com> [180308 21:51]:
> Tim Johnson wrote:
> 
> > :) I'm ready to fly ... and have already been
> > using subr-x thanks, Emanuel
> 
> That was a fun piece of code to write, but in
> all honesty your own suggestion of modifying
> the syntax table is much better, especially if
> you can do it temporarily so it is used
> transparently and won't affect anything else.
  Hmm! Interesting that you brought that up. Been thinking of the
  same. I hate messing with the '.' in python, 'cuz I don't want to mess
  up elpy.

  Having said that, just now am looking at Xah Lee's code at
  http://ergoemacs.org/emacs/elisp_modify_syntax_table_temporarily.html

-- 
Tim 
http://www.akwebsoft.com, http://www.tj49.com



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

* Re: Copy whitespace-delimited text to variable
       [not found]       ` <mailman.10333.1520612428.27995.help-gnu-emacs@gnu.org>
@ 2018-03-11  0:21         ` Emanuel Berg
  2018-03-11 16:18           ` Tim Johnson
       [not found]           ` <mailman.10425.1520785140.27995.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 9+ messages in thread
From: Emanuel Berg @ 2018-03-11  0:21 UTC (permalink / raw)
  To: help-gnu-emacs

Tim Johnson wrote:

> Hmm! Interesting that you brought that up.
> Been thinking of the same. I hate messing
> with the '.' in python, 'cuz I don't want to
> mess up elpy.

(defun backward-word-experiment ()
  (interactive)
  (let ((temp-st (make-syntax-table)))
    (modify-syntax-entry ?. "w" temp-st)
    (with-syntax-table temp-st
      (backward-word 1) )))
(defalias 'bwe 'backward-word-experiment)
;; never fear, g.args is here
                    ^^ try me


"Pacquiao hits Marquez like a typhoon across
the Pacific!"
"And Marquez has never seen anything like
it before!"
"Who has?"
...
"If this levels out, it can be a tremendous
turn of events!"
"Marquez is fighting the fight of his life,
because this is the fight of his life."

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


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

* Re: Copy whitespace-delimited text to variable
  2018-03-11  0:21         ` Emanuel Berg
@ 2018-03-11 16:18           ` Tim Johnson
       [not found]           ` <mailman.10425.1520785140.27995.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Tim Johnson @ 2018-03-11 16:18 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg <moasen@zoho.com> [180310 15:31]:
> Tim Johnson wrote:
> 
> > Hmm! Interesting that you brought that up.
> > Been thinking of the same. I hate messing
> > with the '.' in python, 'cuz I don't want to
> > mess up elpy.
> 
> (defun backward-word-experiment ()
>   (interactive)
>   (let ((temp-st (make-syntax-table)))
>     (modify-syntax-entry ?. "w" temp-st)
>     (with-syntax-table temp-st
>       (backward-word 1) )))
> (defalias 'bwe 'backward-word-experiment)
> ;; never fear, g.args is here
>                     ^^ try me
> 
  This one is definitely the Bee's Knees.
  Adding to moi library.
  tack
-- 
Tim 
http://www.akwebsoft.com, http://www.tj49.com



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

* Re: Copy whitespace-delimited text to variable
       [not found]           ` <mailman.10425.1520785140.27995.help-gnu-emacs@gnu.org>
@ 2018-03-11 22:17             ` Emanuel Berg
  0 siblings, 0 replies; 9+ messages in thread
From: Emanuel Berg @ 2018-03-11 22:17 UTC (permalink / raw)
  To: help-gnu-emacs

Tim Johnson wrote:

>> (defun backward-word-experiment ()
>>   (interactive)
>>   (let ((temp-st (make-syntax-table)))
>>     (modify-syntax-entry ?. "w" temp-st)
>>     (with-syntax-table temp-st
>>       (backward-word 1) )))
>> (defalias 'bwe 'backward-word-experiment)
>> ;; never fear, g.args is here
>>                     ^^ try me
> 
> This one is definitely the Bee's Knees.

Marle: How do we get home?

Lucca: Your Highness, er, Princess... we...

Marle: Please call me Marle!

Lucca: Well then, Marle... Observe!

    (gate opens)

Marle: Wow! Lucca! You're amazing!

Lucca: Ain't it the truth! Oh, um... I mean...


http://www.cot.drackir.com/script3.htm

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


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

end of thread, other threads:[~2018-03-11 22:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.10256.1520462425.27995.help-gnu-emacs@gnu.org>
2018-03-08  6:10 ` Copy whitespace-delimited text to variable Emanuel Berg
2018-03-08  6:37   ` Emanuel Berg
2018-03-08 16:15   ` Tim Johnson
     [not found]   ` <mailman.10281.1520525754.27995.help-gnu-emacs@gnu.org>
2018-03-09  6:47     ` Emanuel Berg
2018-03-09 16:20       ` Tim Johnson
     [not found]       ` <mailman.10333.1520612428.27995.help-gnu-emacs@gnu.org>
2018-03-11  0:21         ` Emanuel Berg
2018-03-11 16:18           ` Tim Johnson
     [not found]           ` <mailman.10425.1520785140.27995.help-gnu-emacs@gnu.org>
2018-03-11 22:17             ` Emanuel Berg
2018-03-07 22:40 Tim Johnson

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.