1

In this example, the function doremi https://www.emacswiki.org/emacs/DoReMi seems to be encountering a problem due to the previous input. Based upon that assumption, I have tried calling discard-input and also setting to nil the variables last-command-event and last-input-event. Q: How can this particular issue be resolved?

If at all possible, the example my-func should remain as-is when crafting a solution to this particular issue. The ultimate goal will be to begin by calling doremi-test-fn with down-mouse-2, extract some goodies from that initial event, then call my-func using the initial event as an argument, then call doremi to select a string from seq, and finally use that selected string to craft a new custom list (in the form of a similuated mouse event) that will be passed as an argument to my-func.

[Due to the need for a minimal working example, my-func is called for the second (2nd) time when doremi exits. However, I plan on calling my-func successively as doremi loops forwards/backwards through seq. Hopefully, the suggested solution will still suffice.]

(defun my-func (init-event)
  (interactive "e")
  (message "my-func:  %s" init-event))

(defun doremi-test-fn (init-event)
  (interactive "e")
  (let* ((init-win (selected-window))
         (seq '("a" "b" "c" "d"))
         (init-val "c")
         (start (event-start init-event))
         (window (posn-window start)) ;; nth 0
         (pos-or-area (posn-area start)) ;; nth 1
         (x-y (posn-x-y start)) ;; nth 2
         (timestamp (posn-timestamp start)) ;; nth 3
         (obj (posn-string start)) ;; nth 4
         (text-pos (posn-point start)) ;; nth 5
         (col-row (posn-actual-col-row start)) ;; nth 6
         (image (posn-image start)) ;; nth 7
         (obj-x-y (posn-object-x-y start)) ;; nth 8
         (obj-w-h (posn-object-width-height start)) ;; nth 9 position
         (the-event
           (list window
                 pos-or-area
                 x-y
                 timestamp
                 obj
                 text-pos
                 col-row
                 image
                 obj-x-y
                 obj-w-h))
         val)
    (my-func init-event)
    (discard-input)
    (setq last-input-event nil
          last-command-event nil)
    (doremi
      (lambda (newval)
        (prog1
          (setq val newval)
          (message "newval: %s" newval)))
      init-val 1 nil seq))
    ;;;
    ;;; Using the selected string from the `doremi' call above, craft a
    ;;; custom list to mimic/simulate the value returned by a mouse event.
    ;;;
    ;;; (my-func the-event--modified)
    )

(global-set-key [down-mouse-2] #'doremi-test-fn)

BACKTRACE

(error "‘doremi’, unexpected event: ‘(mouse-2 (#<window 52 on *TEST*> 20 (173 . 318) 32433130 nil 20 (14 . 2) nil (74 . 278) (11 . 20)))’ - report bug to drew.adams@oracle.com")
  signal(error ("‘doremi’, unexpected event: ‘(mouse-2 (#<window 52 on *TEST*> 20 (173 . 318) 32433130 nil 20 (14 . 2) nil (74 . 278) (11 . 20)))’ - report bug to drew.adams@oracle.com"))
  error("`doremi', unexpected event: `%S' - report bug to %s%s%s%s" (mouse-2 (#<window 52 on *TEST*> 20 (173 . 318) 32433130 nil 20 (14 . 2) nil (74 . 278) (11 . 20))) "drew.adams" "@" "oracle" ".com")
  (cond ((member evnt doremi-up-keys) (setq new-incr incr)) ((member evnt doremi-down-keys) (setq new-incr (if (atom incr) (- incr) (mapcar (function -) incr)))) ((member evnt doremi-boost-up-keys) (setq new-incr (if (atom incr) (* doremi-boost-scale-factor incr) (mapcar (function (lambda (in) (* doremi-boost-scale-factor in))) incr)))) ((member evnt doremi-boost-down-keys) (setq new-incr (if (atom incr) (* doremi-boost-scale-factor (- incr)) (mapcar (function (lambda (in) (* doremi-boost-scale-factor ...))) incr)))) ((and (consp evnt) (equal (quote mouse-wheel) (event-basic-type (car evnt)))) (setq new-incr (if (< 0 (nth 2 evnt)) incr (if (atom incr) (- incr) (mapcar (function -) incr)))) (if (event-modifiers evnt) (progn (setq new-incr (if (atom new-incr) (* doremi-boost-scale-factor new-incr) (mapcar (function ...) new-incr)))))) ((and (consp evnt) (member (event-basic-type (car evnt)) (list wheel-up wheel-down))) (let ((button (mwheel-event-button evnt))) (cond ((eq button mouse-wheel-down-event) (setq new-incr incr)) ((eq button mouse-wheel-up-event) (setq new-incr (if (atom incr) (- incr) (mapcar ... incr)))) (t (error "`doremi', bad mwheel-scroll binding - report bug to %s%s%s%s" "drew.adams" "@" "oracle" ".com")))) (if (if (> emacs-major-version 22) (doremi-intersection (event-modifiers evnt) (quote (shift control meta alt hyper super))) (event-modifiers evnt)) (progn (setq new-incr (if (atom new-incr) (* doremi-boost-scale-factor new-incr) (mapcar (function ...) new-incr)))))) (t (error "`doremi', unexpected event: `%S' - report bug to %s%s%s%s" evnt "drew.adams" "@" "oracle" ".com")))
  (while (progn (setq evnt (if (if (fboundp (quote display-graphic-p)) (display-graphic-p) window-system) (read-event prompt) (read-key prompt)) prompt nil) (or (member evnt keys) (and (consp evnt) (member (event-basic-type (car evnt)) (list (quote switch-frame) (quote mouse-wheel) (quote mouse-2) wheel-up wheel-down))))) (cond ((member evnt doremi-up-keys) (setq new-incr incr)) ((member evnt doremi-down-keys) (setq new-incr (if (atom incr) (- incr) (mapcar (function -) incr)))) ((member evnt doremi-boost-up-keys) (setq new-incr (if (atom incr) (* doremi-boost-scale-factor incr) (mapcar (function (lambda ... ...)) incr)))) ((member evnt doremi-boost-down-keys) (setq new-incr (if (atom incr) (* doremi-boost-scale-factor (- incr)) (mapcar (function (lambda ... ...)) incr)))) ((and (consp evnt) (equal (quote mouse-wheel) (event-basic-type (car evnt)))) (setq new-incr (if (< 0 (nth 2 evnt)) incr (if (atom incr) (- incr) (mapcar (function -) incr)))) (if (event-modifiers evnt) (progn (setq new-incr (if (atom new-incr) (* doremi-boost-scale-factor new-incr) (mapcar ... new-incr)))))) ((and (consp evnt) (member (event-basic-type (car evnt)) (list wheel-up wheel-down))) (let ((button (mwheel-event-button evnt))) (cond ((eq button mouse-wheel-down-event) (setq new-incr incr)) ((eq button mouse-wheel-up-event) (setq new-incr (if ... ... ...))) (t (error "`doremi', bad mwheel-scroll binding - report bug to %s%s%s%s" "drew.adams" "@" "oracle" ".com")))) (if (if (> emacs-major-version 22) (doremi-intersection (event-modifiers evnt) (quote (shift control meta alt hyper super))) (event-modifiers evnt)) (progn (setq new-incr (if (atom new-incr) (* doremi-boost-scale-factor new-incr) (mapcar ... new-incr)))))) (t (error "`doremi', unexpected event: `%S' - report bug to %s%s%s%s" evnt "drew.adams" "@" "oracle" ".com"))) (if (and (consp evnt) (memq (event-basic-type (car evnt)) (quote (mouse-2 switch-frame)))) (message save-prompt) (condition-case failure (setq init-val (cond ((ring-p enum) (if (and allow-new-p ...) (progn ...)) (if (< ... 2) (progn ...)) (let* (... ...) (if ... ... ...))) ((functionp growth-fn) (if (atom new-incr) (if ... ... ...) (if ... ... ...))) (growth-fn (doremi-set-new-value setter-fn new-incr)) ((and (numberp new-incr) (numberp init-val)) (doremi-set-new-value setter-fn (+ init-val new-incr))) (t (error "`doremi' - Bad argument.  INIT-VAL: %S, INCR: %S" init-val new-incr)))) (error (error "%s" (error-message-string failure))))))
  (let ((prompt (format "Use %s, %s, or mouse wheel to adjust value" (single-key-description (car doremi-up-keys)) (single-key-description (car doremi-down-keys)))) (keys (append doremi-up-keys doremi-down-keys doremi-boost-up-keys doremi-boost-down-keys)) (echo-keystrokes 0) (wheel-down mouse-wheel-up-event) (wheel-up mouse-wheel-down-event) evnt save-prompt) (if enum nil (setq prompt (concat prompt " (modifier key: faster)"))) (setq prompt (format (concat prompt ".  Value now: %s") init-val) save-prompt prompt) (while (progn (setq evnt (if (if (fboundp (quote display-graphic-p)) (display-graphic-p) window-system) (read-event prompt) (read-key prompt)) prompt nil) (or (member evnt keys) (and (consp evnt) (member (event-basic-type (car evnt)) (list (quote switch-frame) (quote mouse-wheel) (quote mouse-2) wheel-up wheel-down))))) (cond ((member evnt doremi-up-keys) (setq new-incr incr)) ((member evnt doremi-down-keys) (setq new-incr (if (atom incr) (- incr) (mapcar (function -) incr)))) ((member evnt doremi-boost-up-keys) (setq new-incr (if (atom incr) (* doremi-boost-scale-factor incr) (mapcar (function ...) incr)))) ((member evnt doremi-boost-down-keys) (setq new-incr (if (atom incr) (* doremi-boost-scale-factor (- incr)) (mapcar (function ...) incr)))) ((and (consp evnt) (equal (quote mouse-wheel) (event-basic-type (car evnt)))) (setq new-incr (if (< 0 (nth 2 evnt)) incr (if (atom incr) (- incr) (mapcar ... incr)))) (if (event-modifiers evnt) (progn (setq new-incr (if ... ... ...))))) ((and (consp evnt) (member (event-basic-type (car evnt)) (list wheel-up wheel-down))) (let ((button (mwheel-event-button evnt))) (cond ((eq button mouse-wheel-down-event) (setq new-incr incr)) ((eq button mouse-wheel-up-event) (setq new-incr ...)) (t (error "`doremi', bad mwheel-scroll binding - report bug to %s%s%s%s" "drew.adams" "@" "oracle" ".com")))) (if (if (> emacs-major-version 22) (doremi-intersection (event-modifiers evnt) (quote ...)) (event-modifiers evnt)) (progn (setq new-incr (if ... ... ...))))) (t (error "`doremi', unexpected event: `%S' - report bug to %s%s%s%s" evnt "drew.adams" "@" "oracle" ".com"))) (if (and (consp evnt) (memq (event-basic-type (car evnt)) (quote (mouse-2 switch-frame)))) (message save-prompt) (condition-case failure (setq init-val (cond ((ring-p enum) (if ... ...) (if ... ...) (let* ... ...)) ((functionp growth-fn) (if ... ... ...)) (growth-fn (doremi-set-new-value setter-fn new-incr)) ((and ... ...) (doremi-set-new-value setter-fn ...)) (t (error "`doremi' - Bad argument.  INIT-VAL: %S, INCR: %S" init-val new-incr)))) (error (error "%s" (error-message-string failure)))))) (message nil) (setq unread-command-events (cons evnt unread-command-events)))
  (let ((new-incr incr)) (if (and enum (sequencep enum)) (progn (setq enum (ring-convert-sequence-to-ring enum)))) (let ((prompt (format "Use %s, %s, or mouse wheel to adjust value" (single-key-description (car doremi-up-keys)) (single-key-description (car doremi-down-keys)))) (keys (append doremi-up-keys doremi-down-keys doremi-boost-up-keys doremi-boost-down-keys)) (echo-keystrokes 0) (wheel-down mouse-wheel-up-event) (wheel-up mouse-wheel-down-event) evnt save-prompt) (if enum nil (setq prompt (concat prompt " (modifier key: faster)"))) (setq prompt (format (concat prompt ".  Value now: %s") init-val) save-prompt prompt) (while (progn (setq evnt (if (if (fboundp ...) (display-graphic-p) window-system) (read-event prompt) (read-key prompt)) prompt nil) (or (member evnt keys) (and (consp evnt) (member (event-basic-type ...) (list ... ... ... wheel-up wheel-down))))) (cond ((member evnt doremi-up-keys) (setq new-incr incr)) ((member evnt doremi-down-keys) (setq new-incr (if (atom incr) (- incr) (mapcar ... incr)))) ((member evnt doremi-boost-up-keys) (setq new-incr (if (atom incr) (* doremi-boost-scale-factor incr) (mapcar ... incr)))) ((member evnt doremi-boost-down-keys) (setq new-incr (if (atom incr) (* doremi-boost-scale-factor ...) (mapcar ... incr)))) ((and (consp evnt) (equal (quote mouse-wheel) (event-basic-type ...))) (setq new-incr (if (< 0 ...) incr (if ... ... ...))) (if (event-modifiers evnt) (progn (setq new-incr ...)))) ((and (consp evnt) (member (event-basic-type ...) (list wheel-up wheel-down))) (let ((button ...)) (cond (... ...) (... ...) (t ...))) (if (if (> emacs-major-version 22) (doremi-intersection ... ...) (event-modifiers evnt)) (progn (setq new-incr ...)))) (t (error "`doremi', unexpected event: `%S' - report bug to %s%s%s%s" evnt "drew.adams" "@" "oracle" ".com"))) (if (and (consp evnt) (memq (event-basic-type (car evnt)) (quote (mouse-2 switch-frame)))) (message save-prompt) (condition-case failure (setq init-val (cond (... ... ... ...) (... ...) (growth-fn ...) (... ...) (t ...))) (error (error "%s" (error-message-string failure)))))) (message nil) (setq unread-command-events (cons evnt unread-command-events))))
  doremi((lambda (newval) (prog1 (setq val newval) (message "newval: %s" newval))) "c" 1 nil ("a" "b" "c" "d"))
  (let* ((init-win (selected-window)) (seq (quote ("a" "b" "c" "d"))) (init-val "c") (start (event-start init-event)) (window (posn-window start)) (pos-or-area (posn-area start)) (x-y (posn-x-y start)) (timestamp (posn-timestamp start)) (obj (posn-string start)) (text-pos (posn-point start)) (col-row (posn-actual-col-row start)) (image (posn-image start)) (obj-x-y (posn-object-x-y start)) (obj-w-h (posn-object-width-height start)) (the-event (list window pos-or-area x-y timestamp obj text-pos col-row image obj-x-y obj-w-h)) val) (my-func init-event) (discard-input) (setq last-input-event nil last-input-event nil) (doremi (function (lambda (newval) (prog1 (setq val newval) (message "newval: %s" newval)))) init-val 1 nil seq))
  doremi-test-fn((down-mouse-2 (#<window 52 on *TEST*> 20 (173 . 318) 32432910 nil 20 (14 . 2) nil (74 . 278) (11 . 20))))
  funcall-interactively(doremi-test-fn (down-mouse-2 (#<window 52 on *TEST*> 20 (173 . 318) 32432910 nil 20 (14 . 2) nil (74 . 278) (11 . 20))))
  call-interactively(doremi-test-fn nil nil)
  command-execute(doremi-test-fn)
Drew
  • 75,699
  • 9
  • 109
  • 225
lawlist
  • 18,826
  • 5
  • 37
  • 118

1 Answers1

1

For now at least, try commenting out the last cond' clause (with t) in the code of function doremi` - the one that raises that error:

(t (error "`doremi', unexpected event: `%S' etcetera" evnt))

That should enable it to work for you.

The right fix is likely to move the test and true branch of the if that follows that cond into the cond, just before that last "unexpected event" clause.

That seems to do the right thing. IOW, move that into the cond', and keep the false branch of that ifafter thecond` doing it unconditionally there.

Thanks for the report. I uploaded the fix - please download the latest here: https://www.emacswiki.org/emacs/download/doremi.el

Drew
  • 75,699
  • 9
  • 109
  • 225
  • 1
    Based upon the answer, everything appears to be working now with the test example -- thank you. – lawlist Mar 18 '22 at 01:43