[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: list-at-point
From: |
martin rudalics |
Subject: |
Re: list-at-point |
Date: |
Thu, 12 Oct 2006 17:57:04 +0200 |
User-agent: |
Mozilla Thunderbird 1.0 (Windows/20041206) |
> Seems as function `list-at-point' from thingatpt.el
> fails.
>
Currently `list-at-point' does `up-list' followed by `backward-sexp'
followed by another `up-list' which doesn't make sense. Please look at
the attached - largely untested - patch which also tries to handle the
problem that `sexp-at-point' fails at eob.
*** thingatpt.el.~1.37.~ Sat Sep 23 11:08:56 2006
--- thingatpt.el Thu Oct 12 17:39:06 2006
***************
*** 76,122 ****
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.
! (funcall ;; First move to end.
! (or (get thing 'end-op)
! (lambda () (forward-thing thing 1))))
! (funcall ;; Then move to beg.
! (or (get thing 'beginning-op)
! (lambda () (forward-thing thing -1))))
! (let ((beg (point)))
! (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
(progn
(funcall
(or (get thing 'end-op)
! (lambda () (forward-thing thing 1))))
! (point))))
! (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.
! (funcall ;; First, move to beg.
! (or (get thing 'beginning-op)
! (lambda () (forward-thing thing -1))))
! (funcall ;; Then move to end.
! (or (get thing 'end-op)
! (lambda () (forward-thing thing 1))))
(let ((end (point))
! (real-beg
(progn
(funcall
(or (get thing 'beginning-op)
! (lambda () (forward-thing thing -1))))
(point))))
! (if (and real-beg end (<= real-beg orig) (<= orig end))
! (cons real-beg end))))))
(error nil)))))
;;;###autoload
--- 76,152 ----
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))
! failure bounds)
(condition-case nil
(save-excursion
;; Try moving forward, then back.
! (condition-case nil
! (funcall ;; Move forward.
! (or (get thing 'end-op)
! (lambda () (forward-thing thing 1))))
! (scan-error (setq failure t)))
! (unless failure
! (condition-case nil
! (funcall ;; Move backward.
! (or (get thing 'beginning-op)
! (lambda () (forward-thing thing -1))))
! (scan-error (setq failure t))))
! (unless failure
! (let ((beg (point))
! (end
! (condition-case nil
(progn
(funcall
(or (get thing 'end-op)
! (lambda () (forward-thing thing 1))))
! (point))
! (scan-error (setq failure t)))))
! (if (and (not failure) (<= beg orig) end (<= orig end))
! (setq bounds (cons beg end))
! (setq failure t))))
! (when failure
! (setq failure nil)
! (goto-char orig)
! ;; Try a second time, moving backward first and then forward,
! ;; so that we can find a thing that ends at ORIG.
! (condition-case nil
! (funcall ;; Move backward
! (or (get thing 'beginning-op)
! (lambda () (forward-thing thing -1))))
! (scan-error (setq failure t)))
! (unless failure
! (condition-case nil
! (funcall ;; Move forward.
! (or (get thing 'end-op)
! (lambda () (forward-thing thing 1))))
! (scan-error (setq failure t))))
! (unless failure
(let ((end (point))
! (beg
! (condition-case nil
! (progn
! (funcall
! (or (get thing 'beginning-op)
! (lambda () (forward-thing thing -1))))
! (point))
! (scan-error (setq failure t)))))
! (if (and (not failure) beg (<= beg orig) (<= orig end))
! (setq bounds (cons beg end))
! (setq failure t))))
! (when (and failure (get thing 'up-op))
! ;; Try moving up and then forward.
! (funcall (get thing 'up-op))
! (let ((end (point))
! (beg
(progn
(funcall
(or (get thing 'beginning-op)
! (lambda () (forward-thing thing -1))))
(point))))
! (when (and beg (<= beg orig) (<= orig end))
! (setq bounds (cons beg end))))))
! bounds)
(error nil)))))
;;;###autoload
***************
*** 184,191 ****
;; Lists
! (put 'list 'end-op (lambda () (up-list 1)))
! (put 'list 'beginning-op 'backward-sexp)
;; Filenames and URLs www.com/foo%32bar
--- 214,220 ----
;; Lists
! (put 'list 'up-op (lambda () (up-list 1)))
;; Filenames and URLs www.com/foo%32bar