abo-abo / ace-window

Quickly switch windows in Emacs
972 stars 86 forks source link

Large horizontal scroll causes error #12

Closed holocronweaver closed 9 years ago

holocronweaver commented 9 years ago

When switching windows, occasionally the buffers darken yet no selection characters are displayed in them and hitting keys does nothing until I use C-g to escape ace-window.

An error message appears in the modeline: Args out of range: #<buffer *myBuffer*>, 1713, 1714.

I believe this is referring to the horizontal scroll of myBuffer being too large for ace-window to handle. This happens fairly often to me as I often am editing files with very long lines.

Afterwards the darkened buffers do not return to their original color, remaining dark. I haven't found any way to undo the discoloration except restarting Emacs (reapplying major-mode does not help). Might this discoloration be a failure state in ace-window that doesn't clean up after itself?

So the two bugs seem to be:

  1. Large horizontal scrolls cause ace-window to spit the above error message and fail to allow switching windows.
  2. This failure results in windows remaining dark rather than reverting to original color.
holocronweaver commented 9 years ago

Here is a stack trace using ace-window while a gdb buffer has the pointer at the end of a very long (column 379) command:

Debugger entered--Lisp error: (args-out-of-range #<buffer *gud-rism3d.snglpnt*> 1591 1592)
  ace-jump-buffer-substring([cl-struct-aj-position 1591 [cl-struct-aj-visual-area #<buffer *gud-rism3d.snglpnt*> #<window 17 on *gud-rism3d.snglpnt*> #<frame emacs Prelude - *gud-rism3d.snglpnt* 0x53dc0f0> nil]])
...some lines with bytecode which will not paste into Firefox...
ace-jump-update-overlay-in-search-tree((branch (leaf . #<overlay from 15471 to 15472 in amber_rism_interface.F90>) (leaf . #<overlay from 1264 to 1264 in *gud-rism3d.snglpnt*>) (leaf . #<overlay from 1 to 2 in *scratch*>) (leaf . #<overlay from 477 to 478 in parameters.txt>) (leaf . #<overlay from 1 to 2 in *compilation*>) (leaf . #<overlay from 1 to 2 in *input/output of rism3d.snglpnt*>) (leaf . #<overlay from 1 to 2 in *breakpoints of rism3d.snglpnt*>)) (104 116 110 115 45 103 99 114 108 100 102))
  (let ((candidate-list (mapcar (function (lambda (va) (let (...) (if ... ...)) (make-aj-position :offset (aw-offset ...) :visual-area va))) visual-area-list))) (if ace-jump-mode-gray-background (setq ace-jump-background-overlay-list (let* ((--cl-var-- visual-area-list) (va nil) (--cl-var-- nil)) (while (consp --cl-var--) (setq va (car --cl-var--)) (setq --cl-var-- (cons (let* ... ... ol) --cl-var--)) (setq --cl-var-- (cdr --cl-var--))) (nreverse --cl-var--)))) (setq ace-jump-search-tree (ace-jump-tree-breadth-first-construct (length candidate-list) (length aw-keys))) (ace-jump-populate-overlay-to-search-tree ace-jump-search-tree candidate-list) (ace-jump-update-overlay-in-search-tree ace-jump-search-tree aw-keys) (setq ace-jump-mode " Ace - Window") (force-mode-line-update) (setq overriding-local-map (let ((map (make-keymap))) (let ((--dolist-tail-- aw-keys) key-code) (while --dolist-tail-- (setq key-code (car --dolist-tail--)) (define-key map (make-string 1 key-code) (quote aw-switch-to-window-wrapper)) (setq --dolist-tail-- (cdr --dolist-tail--)))) (define-key map [t] (quote ace-jump-done)) map)) (add-hook (quote mouse-leave-buffer-hook) (quote ace-jump-done)) (add-hook (quote kbd-macro-termination-hook) (quote ace-jump-done)))
  (cond ((eql (length visual-area-list) (quote 0)) nil) ((eql (length visual-area-list) (quote 1)) (if (aw-ignored-p (selected-window)) (other-window 1) (select-window (progn (or (and (memq ... cl-struct-aj-visual-area-tags)) (error "%s accessing a non-%s" (quote aj-visual-area-window) (quote aj-visual-area))) (aref (car visual-area-list) 2))))) ((eql (length visual-area-list) (quote 2)) (if (aw-ignored-p (selected-window)) (other-window 1) (let ((sw (selected-window)) (w (next-window nil nil next-window-scope))) (while (aw-ignored-p w) (select-window w) (setq w (next-window nil nil next-window-scope))) (select-window sw) (aw-switch-to-window w)))) (t (let ((candidate-list (mapcar (function (lambda ... ... ...)) visual-area-list))) (if ace-jump-mode-gray-background (setq ace-jump-background-overlay-list (let* ((--cl-var-- visual-area-list) (va nil) (--cl-var-- nil)) (while (consp --cl-var--) (setq va ...) (setq --cl-var-- ...) (setq --cl-var-- ...)) (nreverse --cl-var--)))) (setq ace-jump-search-tree (ace-jump-tree-breadth-first-construct (length candidate-list) (length aw-keys))) (ace-jump-populate-overlay-to-search-tree ace-jump-search-tree candidate-list) (ace-jump-update-overlay-in-search-tree ace-jump-search-tree aw-keys) (setq ace-jump-mode " Ace - Window") (force-mode-line-update) (setq overriding-local-map (let ((map (make-keymap))) (let ((--dolist-tail-- aw-keys) key-code) (while --dolist-tail-- (setq key-code ...) (define-key map ... ...) (setq --dolist-tail-- ...))) (define-key map [t] (quote ace-jump-done)) map)) (add-hook (quote mouse-leave-buffer-hook) (quote ace-jump-done)) (add-hook (quote kbd-macro-termination-hook) (quote ace-jump-done)))))
 (let ((candidate-list (mapcar (function (lambda (va) (let (...) (if ... ...)) (make-aj-position :offset (aw-offset ...) :visual-area va))) visual-area-list))) (if ace-jump-mode-gray-background (setq ace-jump-background-overlay-list (let* ((--cl-var-- visual-area-list) (va nil) (--cl-var-- nil)) (while (consp --cl-var--) (setq va (car --cl-var--)) (setq --cl-var-- (cons (let* ... ... ol) --cl-var--)) (setq --cl-var-- (cdr --cl-var--))) (nreverse --cl-var--)))) (setq ace-jump-search-tree (ace-jump-tree-breadth-first-construct (length candidate-list) (length aw-keys))) (ace-jump-populate-overlay-to-search-tree ace-jump-search-tree candidate-list) (ace-jump-update-overlay-in-search-tree ace-jump-search-tree aw-keys) (setq ace-jump-mode " Ace - Window") (force-mode-line-update) (setq overriding-local-map (let ((map (make-keymap))) (let ((--dolist-tail-- aw-keys) key-code) (while --dolist-tail-- (setq key-code (car --dolist-tail--)) (define-key map (make-string 1 key-code) (quote aw-switch-to-window-wrapper)) (setq --dolist-tail-- (cdr --dolist-tail--)))) (define-key map [t] (quote ace-jump-done)) map)) (add-hook (quote mouse-leave-buffer-hook) (quote ace-jump-done)) (add-hook (quote kbd-macro-termination-hook) (quote ace-jump-done)))
  (cond ((eql (length visual-area-list) (quote 0)) nil) ((eql (length visual-area-list) (quote 1)) (if (aw-ignored-p (selected-window)) (other-window 1) (select-window (progn (or (and (memq ... cl-struct-aj-visual-area-tags)) (error "%s accessing a non-%s" (quote aj-visual-area-window) (quote aj-visual-area))) (aref (car visual-area-list) 2))))) ((eql (length visual-area-list) (quote 2)) (if (aw-ignored-p (selected-window)) (other-window 1) (let ((sw (selected-window)) (w (next-window nil nil next-window-scope))) (while (aw-ignored-p w) (select-window w) (setq w (next-window nil nil next-window-scope))) (select-window sw) (aw-switch-to-window w)))) (t (let ((candidate-list (mapcar (function (lambda ... ... ...)) visual-area-list))) (if ace-jump-mode-gray-background (setq ace-jump-background-overlay-list (let* ((--cl-var-- visual-area-list) (va nil) (--cl-var-- nil)) (while (consp --cl-var--) (setq va ...) (setq --cl-var-- ...) (setq --cl-var-- ...)) (nreverse --cl-var--)))) (setq ace-jump-search-tree (ace-jump-tree-breadth-first-construct (length candidate-list) (length aw-keys))) (ace-jump-populate-overlay-to-search-tree ace-jump-search-tree candidate-list) (ace-jump-update-overlay-in-search-tree ace-jump-search-tree aw-keys) (setq ace-jump-mode " Ace - Window") (force-mode-line-update) (setq overriding-local-map (let ((map (make-keymap))) (let ((--dolist-tail-- aw-keys) key-code) (while --dolist-tail-- (setq key-code ...) (define-key map ... ...) (setq --dolist-tail-- ...))) (define-key map [t] (quote ace-jump-done)) map)) (add-hook (quote mouse-leave-buffer-hook) (quote ace-jump-done)) (add-hook (quote kbd-macro-termination-hook) (quote ace-jump-done)))))
  (let* ((ace-jump-mode-scope aw-scope) (next-window-scope (cond ((memql aw-scope (quote (quote global))) (quote visible)) ((memql aw-scope (quote (quote frame))) (quote frame)))) (visual-area-list (sort (aw-list-visual-area) (quote aw-visual-area<)))) (if (<= (length visual-area-list) 2) nil (setq visual-area-list (cl-remove-if (function (lambda (va) (let (...) (save-current-buffer ... ...)))) visual-area-list))) (cond ((eql (length visual-area-list) (quote 0)) nil) ((eql (length visual-area-list) (quote 1)) (if (aw-ignored-p (selected-window)) (other-window 1) (select-window (progn (or (and ...) (error "%s accessing a non-%s" ... ...)) (aref (car visual-area-list) 2))))) ((eql (length visual-area-list) (quote 2)) (if (aw-ignored-p (selected-window)) (other-window 1) (let ((sw (selected-window)) (w (next-window nil nil next-window-scope))) (while (aw-ignored-p w) (select-window w) (setq w (next-window nil nil next-window-scope))) (select-window sw) (aw-switch-to-window w)))) (t (let ((candidate-list (mapcar (function ...) visual-area-list))) (if ace-jump-mode-gray-background (setq ace-jump-background-overlay-list (let* (... ... ...) (while ... ... ... ...) (nreverse --cl-var--)))) (setq ace-jump-search-tree (ace-jump-tree-breadth-first-construct (length candidate-list) (length aw-keys))) (ace-jump-populate-overlay-to-search-tree ace-jump-search-tree candidate-list) (ace-jump-update-overlay-in-search-tree ace-jump-search-tree aw-keys) (setq ace-jump-mode " Ace - Window") (force-mode-line-update) (setq overriding-local-map (let ((map ...)) (let (... key-code) (while --dolist-tail-- ... ... ...)) (define-key map [t] (quote ace-jump-done)) map)) (add-hook (quote mouse-leave-buffer-hook) (quote ace-jump-done)) (add-hook (quote kbd-macro-termination-hook) (quote ace-jump-done))))))
  ace-select-window()
  ace-window(1)
  funcall-interactively(ace-window 1)
  #<subr call-interactively>(ace-window nil nil)
  ad-Advice-call-interactively(#<subr call-interactively> ace-window nil nil)
  apply(ad-Advice-call-interactively #<subr call-interactively> (ace-window nil nil))
  call-interactively(ace-window nil nil)
  command-execute(ace-window)
abo-abo commented 9 years ago

Can you reliably reproduce this behavior? In that case, give me a sample file (if necessary) and the sequence of commands that leads to a failure. Once I can reproduce it, I'll be able to see why this happens.

holocronweaver commented 9 years ago
  1. Open a fresh Emacs instance.
  2. Open gdb (M-x gdb).
  3. Enter a line that is very long, say 700 characters (C-u 700 a). Do NOT scroll to the beginning of the very long line - leave the cursor at the end.
  4. Open at least two other windows in the same frame (C-x 3, C-x 3).
  5. Use ace-window (M-x ace-window). You should see an error message such as:
Args out of range: #<buffer *gud-myapp*>, 2448, 2449

Note that it does not matter which window you use ace-window from - the error will still occur.

abo-abo commented 9 years ago

Thanks, I've found that the problem is a bug in the comint-mode. You can check this by evaluating (- (line-end-position) (line-beginning-position)) when the point is positioned like this:

|(gdb)...

So instead of returning 700 it returns 6. I also reproduced this behavior for a Python comint buffer, that one returns 4 instead of 700. I'm guessing this issue will take a while to solve.

holocronweaver commented 9 years ago

Ooh, sounds tricky to get around. Please let me know if I can be of any help. My elisp-fu is weak, but it is getting stronger week by week.

holocronweaver commented 9 years ago

Yes!!! This seems to fix the problem! I have been dealing with this for months. Thanks allot!

Is there a way I could send you some coin?

abo-abo commented 9 years ago

Yes!!! This seems to fix the problem! I have been dealing with this for months. Thanks allot!

You're welcome.

Is there a way I could send you some coin?

No need. I do have a paying job and do this just for fun. Plus I got the answer to this problem on http://emacs.stackexchange.com/ :).

ghost commented 9 years ago

I'm getting the same behavior in an ipython interpreter.

To reproduce:

1. open ipython buffer
2. write globals()<RET> a couple of times to produce a lot of output.
3. press the ace-window combo.

Now you should not see any selection letter in the ipython window. However, if you move up a few lines and try again the ace-window letter will show. If you move down again and try ace-window it won't work.

24.5, OS X, latest ace-window probably (I always get the latest updates from paradox.

Not expecting you to do anything about it, just reporting it in case you are interested.

abo-abo commented 9 years ago

To reproduce:

The recipe doesn't provide the window configuration. I opened 3 ipython windows, just it case, it works fine.

ghost commented 9 years ago

Triple windows split vertically. Thanks, for checking, I guess it is just me then.

abo-abo commented 9 years ago

Triple windows split vertically

Can't reproduce, with either graphical or emacs -nw. It could be OSX specific. If I could reproduce it on GNU/Linux, I'd probably be able to fix it.