From: "Buchs, Kevin J." <buchs.kevin@mayo.edu>
To: help-gnu-emacs@gnu.org
Subject: updating buffer window while accepting minibuffer input
Date: Wed, 16 Jul 2014 16:12:57 -0500 [thread overview]
Message-ID: <9025b1$hrbs0b@ironport9.mayo.edu> (raw)
In-Reply-To: <mailman.161.1405526455.3403.help-gnu-emacs@gnu.org>
This is a follow-up to "regexp nirvana - near miss" (thanks Drew for
giving me this programming burden ;-). I'm wanting to traverse a list of
buffer positions according to minibuffer keystrokes and have the
referenced buffer position update (and eventually highlight) much like
isearch-*. I'm stuck on the buffer position not actually updating
whilest I am in the midst of (read-minibuffer-input). I have spent about
two hours delving into how isearch works and came out without a clue as
to how it actually gets minibuffer reading activated. So, I'm seeking
help. Code follows signature.
Kevin Buchs Research Computer Services Phone: 507-538-5459
Mayo Clinic 200 1st. St SW Rochester, MN 55905
http://mayoclinic.org http://facebook.com/MayoClinic http://youtube.com/MayoClinic http://twitter.com/MayoClinic
(defun regexpneg-fwd ()
(interactive)
;; Move to next match
(if (< regexpneg-pointer (1- (length regexpneg-list)))
(progn
(set-buffer regexpneg-buffer)
(setq regexpneg-pointer (1+ regexpneg-pointer))
(goto-char (nth regexpneg-pointer regexpneg-list))
(recenter 5)
(message "buffer: %S, position: %d, pointer: %d"
(current-buffer) (point) regexpneg-pointer))))
(defun regexpneg-rev ()
(interactive)
;; Move to prior match
(unless (= regexpneg-pointer 0)
(set-buffer regexpneg-buffer)
(setq regexpneg-pointer (1- regexpneg-pointer))
(goto-char (nth regexpneg-pointer regexpneg-list))
(recenter 5)
(message "buffer: %S, position: %d, pointer: %d"
(current-buffer) (point) regexpneg-pointer)))
(defun regexpneg (part negpart)
"Search for regexp part, not followed by regexp negpart; You can
advance in search hits with C-s or SPACE. Reverse with C-r or DEL"
(interactive)
(let (
(point-start (point))
(subsetnotlist '()))
;; Save a reference to current buffer
(setq regexpneg-buffer (current-buffer))
;; Search for 'part' - return list of locations =
regexpneg-list
(setq regexpneg-list '())
(while (re-search-forward part nil t)
(setq regexpneg-list (append regexpneg-list
(list (match-beginning 0)))))
;; Search for 'part'+'negpart' - return list of locations =
subsetnotlist
(goto-char point-start)
(while (re-search-forward (concat part negpart) nil t)
(setq subsetnotlist (append subsetnotlist (list
(match-beginning 0)))))
;; Delete members of subsetnotlist from regexpneg-list
(dolist (var subsetnotlist)
(delq var regexpneg-list))
;; Check for keymap or create it
(unless (keymapp 'regexpneg-keymap)
(setq regexpneg-keymap (make-sparse-keymap))
(define-key regexpneg-keymap "\C-s" 'regexpneg-fwd)
(define-key regexpneg-keymap " " 'regexpneg-fwd)
(define-key regexpneg-keymap "\C-r" 'regexpneg-rev)
(define-key regexpneg-keymap "DEL" 'regexpneg-rev)
(define-key regexpneg-keymap "\C-j" 'exit-minibuffer)
(define-key regexpneg-keymap "\C-m" 'exit-minibuffer))
;; Set index-pointer
(setq regexpneg-pointer 0)
;; Move to first match
(goto-char (nth regexpneg-pointer regexpneg-list))
(message "buffer: %S, position: %d, pointer: %d"
(current-buffer) (point) regexpneg-pointer)
;; Show minibuffer for further options
(setq resp (read-from-minibuffer
"REN: fwd=C-s,SPACE; rev=C-r,DEL; exit=C-j,C-m: " nil
regexpneg-keymap))
(message "got response '%s'" resp)))
next parent reply other threads:[~2014-07-16 21:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.161.1405526455.3403.help-gnu-emacs@gnu.org>
2014-07-16 21:12 ` Buchs, Kevin J. [this message]
2014-07-16 21:50 ` updating buffer window while accepting minibuffer input Drew Adams
2014-07-17 0:52 ` Michael Heerdegen
2014-07-17 1:43 ` Drew Adams
2014-07-17 2:43 ` Michael Heerdegen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='9025b1$hrbs0b@ironport9.mayo.edu' \
--to=buchs.kevin@mayo.edu \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).