From: Deniz Dogan <deniz.a.m.dogan@gmail.com>
To: ishi soichi <soichi777@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Elisp code to choose a region covering a word
Date: Thu, 18 Nov 2010 12:46:03 +0100 [thread overview]
Message-ID: <AANLkTi=+=3+88+ti2TS+FfYDFQesnAi77bqdrRxvG7GV@mail.gmail.com> (raw)
In-Reply-To: <AANLkTik43mPxWFF+dF_cF5DcxJR+nGd_h1JEF3iyxasQ@mail.gmail.com>
2010/11/18 ishi soichi <soichi777@gmail.com>:
> I am trying to develop an elisp program that sets a region covering a word
> in text.
> I am a newbie in elisp so please be adviced.
> For example, we have a text like...
> ----------------------------
> In late 2008, it (<=point here!!!) reduced its interest to 13 percent to
> raise much-needed cash, in a move that many saw as the beginning of a
> distancing of the long-time partners. Ford's stake fell further to 11
> percent when Mazda issued new shares last year.
> ----------------------
> by tying "C-f" (I know it's not a good idea to override "C-f". It's a test),
> the region is set to be
> ----------------------------
> In late 2008, it (Mark here!!!=>) reduced(<=point here!!!) its interest to
> 13 percent to raise much-needed cash, in a move that many saw as the
> beginning of a distancing of the long-time partners. Ford's stake fell
> further to 11 percent when Mazda issued new shares last year.
> ----------------------
> by typing "C-f" again, the region would be
> ----------------------------
> In late 2008, it reduced (Mark here!!!=>)its(<=point here!!!) interest to 13
> percent to raise much-needed cash, in a move that many saw as the beginning
> of a distancing of the long-time partners. Ford's stake fell further to 11
> percent when Mazda issued new shares last year.
> ----------------------
> and so on. Every time we execute the interactive function, each individual
> word is chosen. So I tried,
> ;;-------------------------
> (defun word-choice ()
> (interactive)
> (let (foo)
> (re-search-forward "\\w")
> (goto-char (match-beginning 0))
> (setq foo (point-marker))
> (re-search-forward "\\s ")
> (goto-char (match-beginning 0))
> ))
> (define-key global-map "\C-f" 'word-choice)
> ;;---------------------------
> Obviously it does not do the job. I don't think it sets a mark at all.
> Maybe the use of "point-marker" is wrong.
> Could anyone help me for it?
> soichi
To put a region around the word following point in the buffer you can
use C-s C-w and then continue hitting C-w to extend the region to
include more words. This is not what you were looking for, but I
figured you may want to know about it anyways.
Here is a naive function I just put together:
(defun select-following-word ()
(interactive)
(re-search-forward "\\S-")
(push-mark)
(forward-word))
It works by first moving point to the first non-whitespace character
following current point, then pushing the mark and then moving a word
forward. This effectively sets the region around the following word,
but you may want to massage this code a bit to have it work in certain
corner cases.
You may also want to know about `kbd' which could simplify your keybindings:
(global-set-key (kbd "C-f") ;; easier on the eyes
'select-following-word)
--
Deniz Dogan
next prev parent reply other threads:[~2010-11-18 11:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-18 10:22 Elisp code to choose a region covering a word ishi soichi
2010-11-18 11:45 ` Tassilo Horn
2010-11-18 12:10 ` Tassilo Horn
2010-11-18 15:31 ` Drew Adams
2010-11-18 11:46 ` Deniz Dogan [this message]
2010-11-19 6:49 ` ishi soichi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='AANLkTi=+=3+88+ti2TS+FfYDFQesnAi77bqdrRxvG7GV@mail.gmail.com' \
--to=deniz.a.m.dogan@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=soichi777@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.