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

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

bounds-of-thing-at-point


From: Nils Klarlund
Subject: bounds-of-thing-at-point
Date: 31 Jul 2001 09:59:35 -0400

This bug report will be sent to the Free Software Foundation,
 not to your local site managers!!
Please write in English, because the Emacs maintainers do not have
translators to read other languages for them.

In GNU Emacs 20.7.1 (i386-*-nt5.0.2195)
 of Tue Jun 13 2000 on buffy
configured using `configure NT'

Please describe exactly what actions triggered the bug and the precise
symptoms of the bug:

One possible manifestation: this bug makes (thing-at-point 'sentence)
return nil at the end of the buffer even if a sentence is present.

The first half of the algorithm in bounds-of-thing-at-point would
erroneously terminate the whole function call when an error was
signaled by the forward-x function at the end of the buffer;
correction: protect various calls with local condition-case constructs
as illustrated below.

/Nils

---

(defun bounds-of-thing-at-point (thing)
  "Determine the start and end buffer locations for the THING at point.
THING is a symbol which specifies the kind of syntactic entity you want.
Possibilities include `symbol', `list', `sexp', `defun', `filename', `url',
`word', `sentence', `whitespace', `line', `page' and others.

See the file `thingatpt.el' for documentation on how to define
a symbol as a valid THING.

The value is a cons cell (START . END) giving the start and end positions
of the textual entity that was found."
  (if (get thing 'bounds-of-thing-at-point)
      (funcall (get thing 'bounds-of-thing-at-point))
    (let ((orig (point)))
      (condition-case nil
          (save-excursion
            ;; Try moving forward, then back.
            (let ((end (condition-case nil
                           (progn (funcall 
                                   (or (get thing 'end-op) 
                                       (function (lambda () (forward-thing
                                                             thing 1)))))
                                  (point)) 
                         (error nil)))
                  (beg (condition-case nil
                           (progn 
                             (funcall 
                              (or (get thing 'beginning-op) 
                                  (function (lambda () (forward-thing thing 
-1)))))
                             (point))
                         (error nil))))
              (if (not (and beg (> beg orig)))
                  ;; If that brings us all the way back to ORIG,
                  ;; it worked.  But END may not be the real end.
                  ;; So find the real end that corresponds to BEG.
                  (let ((real-end
                         (condition-case nil
                             (progn 
                               (funcall 
                                (or (get thing 'end-op) 
                                    (function (lambda () (forward-thing thing 
1)))))
                               (point))
                           (error nil))))
                    (if (and beg real-end (<= beg orig) (<= orig real-end))
                        (cons beg real-end)))
                (goto-char orig)
                ;; Try a second time, moving backward first and then forward,
                ;; so that we can find a thing that ends at ORIG.
                (let ((beg (progn 
                             (funcall 
                              (or (get thing 'beginning-op) 
                                  (function (lambda () (forward-thing thing 
-1)))))
                             (point)))
                      (end (progn 
                             (funcall 
                              (or (get thing 'end-op) 
                                  (function (lambda () (forward-thing thing 
1)))))
                             (point)))
                      (real-beg
                       (progn 
                         (funcall 
                          (or (get thing 'beginning-op) 
                              (function (lambda () (forward-thing thing -1)))))
                         (point))))
                  (if (and real-beg end (<= real-beg orig) (<= orig end))
                      (cons real-beg end))))))
        (error nil)))))




reply via email to

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