Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect window start position #127

Merged
merged 5 commits into from Jul 15, 2017
Merged

Conversation

cipharius
Copy link
Contributor

If the value of scroll-margin is not 0, the live buffer won't align with source code buffer properly.

Wasn't sure whether to compensate for scroll-margin manually, so decided to set it to 0 locally for sake of simplicity.

If the value of `scroll-margin` is not 0, the live buffer won't align with source code buffer properly.

Wasn't sure whether to compensate for `scroll-margin` manually, so decided to set it to 0 locally for sake of simplicity.
@codecov-io
Copy link

codecov-io commented Jul 10, 2017

Codecov Report

Merging #127 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #127   +/-   ##
=======================================
  Coverage   99.28%   99.28%           
=======================================
  Files           4        4           
  Lines         985      985           
=======================================
  Hits          978      978           
  Misses          7        7

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 96f22fe...f5747b3. Read the comment docs.

@donkirkby
Copy link
Owner

Thanks for the commit, I didn't know about scroll-margin. I can reproduce the problem, but the commit doesn't seem to fix it. Maybe the problem I found isn't the same as yours. Please post your steps to reproduce the problem, and tell me whether your commit works for you with the problem described here.

Here are the steps I used to reproduce the problem:

  1. Open a python file: emacs foo.py
  2. Type some Python code that is more than one screen.
  3. M-x live-py-mode
  4. M-x set-variable scroll-margin 3
  5. Scroll off the screen.

Expected result: display stays lined up with the code.

Actual result: display is off by 3 lines.

@@ -147,6 +147,7 @@ When the source buffer is narrowed the trace buffer remains
aligned but will not hide the part after the narrowing."
(let* ((output-window (get-buffer-window live-py-trace-name))
(point-min-pos (point-min))
(scroll-margin 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest

(let ((scroll-margin 0)) (recenter-top-bottom 0))

instead to make it clear where the setting is needed.

@brandm
Copy link
Contributor

brandm commented Jul 13, 2017

  1. Open a python file: emacs foo.py
  2. Type some Python code that is more than one screen.
  3. M-x live-py-mode
  4. M-x set-variable scroll-margin 3
  5. Scroll off the screen.

With Emacs 25.2 and 25.1 (tried no older) I can reproduce the issue and the fix.

@cipharius
Copy link
Contributor Author

@donkirkby Yeah, that is the same issue. After tinkering around some more, I managed to break the commit as well.

It seems that instead of using let, the scroll-margin has to be set locally for the output buffer.

In the af9bd0b commit I also simplified the update scroll function a bit.

As for the 85aefe3 commit, it's supposed to be an idea for aligning the source code and output buffer line count, to avoid misaligned code when the source has more lines than output and point is at the end of the buffer. Wasn't sure where to put the code though.

@donkirkby
Copy link
Owner

That works for me, now. Thanks.

Adding the extra lines broke some of the emacs tests, do you want to fix them, or would you like me to do it? You can see the failures more clearly by running them interactively. There are instructions in the test file, but I ran them like this:

emacs -Q -nw -L emacs-live-py-mode -L plugin/PySrc -l live-py-mode.el -l live-py-test.el -f ert-run-tests-interactively

If you're not familiar with the test summary (I wasn't), the docs are helpful.

There are two more broken tests that have something to do with abandoning an open window. @brandm might be able to clarify why they're failing.

(save-restriction
(widen)
(line-number-at-pos point-min-pos)))))
(point-min-line-nr (count-lines 1 (point-min)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice solution to compensate for narrowing.

(recenter-top-bottom 0)
(forward-line (- point-line-nr window-start-line-nr)))
(set-window-buffer output-window live-py-trace-name)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This move breaks

live-py-test/3-other-window/4-abandon-source-and-swap/edit
live-py-test/3-other-window/4-abandon-source-and-swap/move

What issue is the move expected to fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, alright, didn't know it was that important. Just seemed odd to display a buffer that was already checked as visible.

@@ -170,7 +165,7 @@ aligned but will not hide the part after the narrowing."
;; interactivity when `debug-on-error' is active, so it is easily possible
;; to miss the error. And on such an error the function will be removed
;; from `post-command-hook' which is confusing when not noticed.
(when (memq this-command '(narrow-to-region next-line viper-goto-line))
(when (memq this-command '(narrow-to-region next-line previous-line viper-goto-line))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For performance reasons this list should be as short as possible because it requires a redisplay for reasons explained in the comments. Why add previous-line? If it is just for symmetry with next-line then please remove previous-line again and if it helps add a comment below the comment for next-line that it is not in the list intentionally.

@@ -207,6 +202,7 @@ aligned but will not hide the part after the narrowing."
(get-buffer-create live-py-trace-name)
(with-current-buffer live-py-trace-name
(setq-local truncate-lines t)
(setq-local scroll-margin 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable.

@brandm
Copy link
Contributor

brandm commented Jul 15, 2017

Wasn't sure where to put the code though.

If the backend would add the extra lines for the line count alignment instead of the Emacs frontend then the other frontends would benefit as well.

@brandm
Copy link
Contributor

brandm commented Jul 15, 2017

Adding the extra lines broke some of the emacs tests,

Yes, the expected output buffer live-py-test-trace needs the line count aligned.

@cipharius
Copy link
Contributor Author

Alright, fixed the mentioned issues and moved the line alignment to the live-py backend.

I ran the tests and two of them failed due to the appended lines, but that's obviously intentional in this case.

@donkirkby donkirkby merged commit 5af78c0 into donkirkby:master Jul 15, 2017
@donkirkby
Copy link
Owner

I fixed the broken unit tests by adding some extra blank lines.

Thanks for the fix, @ZarsBranchkin, and thanks for the review, @brandm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants