[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Text property searching
From: |
Lars Ingebrigtsen |
Subject: |
Re: Text property searching |
Date: |
Mon, 16 Apr 2018 23:18:54 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
João Távora <address@hidden> writes:
> 1. What should happen if search starts in the region where the
> property is already set?
I've reconsidered slightly after rewriting a couple of functions to use
this.
A typical use case is the user hitting TAB to go to the next button in a
buffer. That would then be something like
(when (get-text-property (point) 'shr-url)
(text-property-search-forward 'shr-url nil t))
(text-property-search-forward 'shr-url nil nil)
I mean, it's not awful, but it's a common use case, and that's boring to
have to type.
So I added a flag, and you can now skip matches under point.
This function:
(defun shr-next-link ()
"Skip to the next link."
(interactive)
(let ((current (get-text-property (point) 'shr-url))
(start (point))
skip)
(while (and (not (eobp))
(equal (get-text-property (point) 'shr-url) current))
(forward-char 1))
(cond
((and (not (eobp))
(get-text-property (point) 'shr-url))
;; The next link is adjacent.
(message "%s" (get-text-property (point) 'help-echo)))
((or (eobp)
(not (setq skip (text-property-not-all (point) (point-max)
'shr-url nil))))
(goto-char start)
(message "No next link"))
(t
(goto-char skip)
(message "%s" (get-text-property (point) 'help-echo))))))
Can now be rewritten as:
(defun shr-next-link ()
"Skip to the next link."
(interactive)
(if (not (text-property-search-forward 'shr-url nil nil t))
(message "No next link")
(message "%s" (get-text-property (point) 'help-echo))))
:-)
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
- Re: Text property searching, (continued)
- Re: Text property searching, Alan Mackenzie, 2018/04/17
- Re: Text property searching, Lars Ingebrigtsen, 2018/04/17
- Re: Text property searching, Alan Mackenzie, 2018/04/17
- Re: Text property searching, Lars Ingebrigtsen, 2018/04/17
- Re: Text property searching, Alan Mackenzie, 2018/04/16
- Re: Text property searching, Lars Ingebrigtsen, 2018/04/16
- Re: Text property searching, Alan Mackenzie, 2018/04/16
- Re: Text property searching, Lars Ingebrigtsen, 2018/04/16
Re: Text property searching,
Lars Ingebrigtsen <=
Re: Text property searching, Lars Ingebrigtsen, 2018/04/16