unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* updating buffer window while accepting minibuffer input
       [not found] <mailman.161.1405526455.3403.help-gnu-emacs@gnu.org>
@ 2014-07-16 21:12 ` Buchs, Kevin J.
  2014-07-16 21:50   ` Drew Adams
  2014-07-17  0:52   ` Michael Heerdegen
  0 siblings, 2 replies; 5+ messages in thread
From: Buchs, Kevin J. @ 2014-07-16 21:12 UTC (permalink / raw)
  To: help-gnu-emacs

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)))





^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: updating buffer window while accepting minibuffer input
  2014-07-16 21:12 ` updating buffer window while accepting minibuffer input Buchs, Kevin J.
@ 2014-07-16 21:50   ` Drew Adams
  2014-07-17  0:52   ` Michael Heerdegen
  1 sibling, 0 replies; 5+ messages in thread
From: Drew Adams @ 2014-07-16 21:50 UTC (permalink / raw)
  To: Buchs, Kevin J., help-gnu-emacs

> 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. 

The Isearch code is a bit complicated.  If you follow its model then you
will likely need to do many of the state-maintenance etc. things it does,
which are not necessarily directly related to searching.

Of particular note: Isearch does not really use the minibuffer (except
for odd jobs like when you use `M-e' to edit the search string).

Instead, it handles events in the usual way that Emacs does.  (In Emacs,
every key you hit corresponds to a command, which is then invoked.)

In Isearch, certain input events correspond to keys that are bound to
particular Isearch actions.  Other keys, such as `a', `B', `9', and `$'
have, as their corresponding action, to add the corresponding printable
character (`a', `B', `9', `$' etc.) to the search string.  Search then
begins again automatically (resumes), using the newly updated search string.
See `isearch-printing-char' for the treatment of printable chars.

In sum, the minibuffer is not involved at all, for reading your input.
In particular, you do *not* want to use `read-input-from-minibuffer',
if you want Isearch-like behavior.

(FWIW, I'm no expert on Isearch.  HTH.  Juri Linkov is one of the best
placed to answer questions about its code.)



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: updating buffer window while accepting minibuffer input
  2014-07-16 21:12 ` updating buffer window while accepting minibuffer input Buchs, Kevin J.
  2014-07-16 21:50   ` Drew Adams
@ 2014-07-17  0:52   ` Michael Heerdegen
  2014-07-17  1:43     ` Drew Adams
  1 sibling, 1 reply; 5+ messages in thread
From: Michael Heerdegen @ 2014-07-17  0:52 UTC (permalink / raw)
  To: help-gnu-emacs

"Buchs, Kevin J." <buchs.kevin@mayo.edu> writes:

> This is a follow-up to "regexp nirvana - near miss" (thanks Drew for
> giving me this programming burden ;-).

BTW, what nobody said yet is that both Icicles and Helm implement buffer
searches that allow negation, i.e., have built in what you described in
your prior post.  Before you reinvent the wheel ... maybe you find one
of these sufficient.

In Icicles' search, use the normal candidate exclusion mechanism.

In helm, use helm-occur and enter e.g. "rx1 !rx1rx2" to match lines that
match regexp rx1, but that do not match regexp rx1 followed by regexp
rx2  ("!" just means "negation").


Michael.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: updating buffer window while accepting minibuffer input
  2014-07-17  0:52   ` Michael Heerdegen
@ 2014-07-17  1:43     ` Drew Adams
  2014-07-17  2:43       ` Michael Heerdegen
  0 siblings, 1 reply; 5+ messages in thread
From: Drew Adams @ 2014-07-17  1:43 UTC (permalink / raw)
  To: Michael Heerdegen, help-gnu-emacs

> In Icicles' search, use the normal candidate exclusion mechanism.

Which means:

1. Type a pattern to match whatever subset of the current
   set of candidates you want to remove (exclude, subtract).

2. Then use `C-~' to remove them.

See "Chip Away the Non-Elephant" in the Icicles doc:
http://www.emacswiki.org//Icicles_-_Nutshell_View#ChippingAway




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: updating buffer window while accepting minibuffer input
  2014-07-17  1:43     ` Drew Adams
@ 2014-07-17  2:43       ` Michael Heerdegen
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Heerdegen @ 2014-07-17  2:43 UTC (permalink / raw)
  To: help-gnu-emacs

Drew Adams <drew.adams@oracle.com> writes:

> > In Icicles' search, use the normal candidate exclusion mechanism.
>
> Which means:
>
> 1. Type a pattern to match whatever subset of the current
>    set of candidates you want to remove (exclude, subtract).
>
> 2. Then use `C-~' to remove them.
>
> See "Chip Away the Non-Elephant" in the Icicles doc:
> http://www.emacswiki.org//Icicles_-_Nutshell_View#ChippingAway

Thanks for elaborating, Drew.


Let me add: the poor man's version of this - or of doing this similarly
with helm - without using external packages could be reached with M-x
occur combined with M-x hide-lines.  Doesn't offer all the features that
come with these packages, but does the job.

Michael.




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-07-17  2:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.161.1405526455.3403.help-gnu-emacs@gnu.org>
2014-07-16 21:12 ` updating buffer window while accepting minibuffer input Buchs, Kevin J.
2014-07-16 21:50   ` Drew Adams
2014-07-17  0:52   ` Michael Heerdegen
2014-07-17  1:43     ` Drew Adams
2014-07-17  2:43       ` Michael Heerdegen

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).