From cd215e056fd092bef5c0867ecd151107516cac09 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 14 Jan 2015 22:47:44 -0200 Subject: Implement sx--find-in-buffer --- sx.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'sx.el') diff --git a/sx.el b/sx.el index af4ab4d..d6c5335 100644 --- a/sx.el +++ b/sx.el @@ -274,6 +274,26 @@ If DIRECTION is negative, move backwards instead." (goto-char (funcall func (point) prop nil limit)) (get-text-property (point) prop))) +(defun sx--find-in-buffer (type id) + "Move point to an object of TYPE and ID. +That is, move forward from beginning of buffer until +`sx--data-here' is an object of type TYPE with the respective id +ID. + +TYPE is either question, answer, or comment. +ID is an integer." + (goto-char (point-min)) + (let (done) + (while (not done) + (let-alist (sx--goto-property-change 'sx--data-here 1) + (setq done (or (eobp) + (= id (cl-case type + (answer .answer_id) + (comment .comment_id) + (question .question_id))))))) + (unless done + (sx-message "Can't find the specified %s" type)))) + ;;; Printing request data (defvar sx--overlays nil -- cgit v1.2.3