[glug-t] Re: emacs search !
- From: "Vimal Joseph" <vimal@xxxxxxxxxxxxx>
- To: glug_t@xxxxxxxxxxxxx
- Date: Wed, 9 Mar 2005 21:51:04 +0530 (IST)
On Wed, 2005-03-09 at 21:22 +0530, me wrote:
On Wed, 2005-03-09 at 14:46 +0000, Senthil Sargunan wrote:
> Hello,
> >
> > Is there a way to search the string on which the cursor is placed without
> > typing the words in EMACS.
> >
>
> add the following lines to your .emacs
>
>
sorry for my quick'n'buggy rply... it is not the correct way doing this...
I found the following snippet at
http://www.emacswiki.org/cgi-bin/wiki/VagnJohansen
Which will work for you.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
VagnJohansen
Elisp Snippets
My version of VIs * and #
The following two functions examines the symbol (mode specific "word")
under the cursor and finds the next and previous occurence, respectively,
of the symbol. Wraparound is supported. Note that they only make sense if
bound to keys. For example:
(global-set-key [C-M-down] 'vjo-forward-current-word-keep-offset)
(global-set-key [C-M-up] 'vjo-backward-current-word-keep-offset)
The keep-offset part means that the offset into the symbol is the same
after moving the point.
It is kinda like a shortcut for M-b C-s C-w C-s.
The code
(defun vjo-forward-current-word-keep-offset ()
" (Vagn Johansen 1999)"
(interactive)
(let ((re-curword) (curword) (offset (point))
(old-case-fold-search case-fold-search) )
(setq curword (thing-at-point 'symbol))
(setq re-curword (concat "\\<" (thing-at-point 'symbol) "\\>") )
(beginning-of-thing 'symbol)
(setq offset (- offset (point))) ; offset from start of symbol/word
(setq offset (- (length curword) offset)) ; offset from end
(forward-char)
(setq case-fold-search nil)
(if (re-search-forward re-curword nil t)
(backward-char offset)
;; else
(progn (goto-char (point-min))
(if (re-search-forward re-curword nil t)
(progn (message "Searching from top. %s" (what-line))
(backward-char offset))
;; else
(message "Searching from top: Not found"))
))
(setq case-fold-search old-case-fold-search)
))
(defun vjo-backward-current-word-keep-offset ()
" (Vagn Johansen 2002)"
(interactive)
(let ((re-curword) (curword) (offset (point))
(old-case-fold-search case-fold-search) )
(setq curword (thing-at-point 'symbol))
(setq re-curword (concat "\\<" curword "\\>") )
(beginning-of-thing 'symbol)
(setq offset (- offset (point))) ; offset from start of symbol/word
(forward-char)
(setq case-fold-search nil)
(if (re-search-backward re-curword nil t)
(forward-char offset)
;; else
(progn (goto-char (point-max))
(if (re-search-backward re-curword nil t)
(progn (message "Searching from bottom. %s" (what-line))
(forward-char offset))
;; else
(message "Searching from bottom: Not found"))
))
(setq case-fold-search old-case-fold-search)
))
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
~vimal
--
Free as in Freedom <www.gnu.org>
---------------------------------------------------------------
To unsubscribe send a mail to glug_t-request@xxxxxxxxxxxxx with
'unsubscribe' as subject.
Website: http://glugt.linuxisle.com
Other related posts: