emacs-devel
[Top][All Lists]
Advanced

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

beginning-of-thing-pos, end-of-thing-pos


From: Andreas Röhler
Subject: beginning-of-thing-pos, end-of-thing-pos
Date: Sun, 19 Aug 2007 16:46:39 +0200
User-agent: KMail/1.8.2

Hi,

at several occasions I needed the buffer-position of a
string (thing).

As I wrote my own thingatpt-utils, already have that. 

But would prefer to keep every code as much
as possible conform with distribution.

Therefore my request for a (very) simple addition:

thingatpt.el knows about THING's position:

(defun beginning-of-thing (thing)
  (let ((bounds (bounds-of-thing-at-point thing)))
    (or bounds (error "No %s here" thing))
    (goto-char (car bounds))))

(defun end-of-thing (thing)
  (let ((bounds (bounds-of-thing-at-point thing)))
    (or bounds (error "No %s here" thing))
    (goto-char (cdr bounds))))

As visible, these functions move point rather than
returning the pos. Simply need some reduction:

(defun beginning-of-thing-pos (thing)
  (let ((bounds (bounds-of-thing-at-point thing)))
    (or bounds (error "No %s here" thing))
    (car bounds)))

(defun end-of-thing-pos (thing)
  (let ((bounds (bounds-of-thing-at-point thing)))
    (or bounds (error "No %s here" thing))
    (cdr bounds)))

Afterwards things like that are possible:

(defun end-of-word-at-point ()
  " "
  (interactive)
  (message "%s" (end-of-thing-pos 'word)))

May `beginning-of-thing-pos' and `end-of-thing-pos'
be included?

Thanks

Andreas Roehler







reply via email to

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