From 5735a30d59af16ba004a151b6e0a4c18ba1d481e Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Tue, 2 Sep 2014 18:16:42 +0300 Subject: [PATCH] Fix bug #18384 with incorrect reporting of row number by posn-col-row. lisp/subr.el (posn-col-row): Revert the change from commit 2010-11-13T21:07:58Z!eliz@gnu.org, which was inadvertently merged from emacs-23 release branch in 2010-11-18T03:54:14Z!monnier@iro.umontreal.ca, and introduced an off-by-one error in the reported row when there is a header line. src/dispnew.c (buffer_posn_from_coords): Fix an off-by-one error in the reported row in the case of a window with a header line, by improving on the fix committed in 2011-10-08T10:58:50Z!eliz@gnu.org eliz@gnu.org-20111008105850-ht4tvsayohvr1kjc. --- lisp/ChangeLog | 9 +++++++++ lisp/subr.el | 5 +---- src/ChangeLog | 7 +++++++ src/dispnew.c | 16 ++++++++-------- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 70e5ade2eee..f729f42da87 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2014-09-02 Eli Zaretskii + + * subr.el (posn-col-row): Revert the change from commit + 2010-11-13T21:07:58Z!eliz@gnu.org, which + was inadvertently merged from emacs-23 release branch in 2010-11-18T03:54:14Z!monnier@iro.umontreal.ca + monnier@iro.umontreal.ca-20101118035414-yvlg7k7dk4k4l3q, and + introduced an off-by-one error in the reported row when there is a + header line. (Bug#18384) + 2014-09-01 Fabián Ezequiel Gallina * progmodes/python.el (python-indent-post-self-insert-function): diff --git a/lisp/subr.el b/lisp/subr.el index 116032fd0ba..089e3efe79c 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -1146,10 +1146,7 @@ and `event-end' functions." ((null spacing) (setq spacing 0))) (cons (/ (car pair) (frame-char-width frame)) - (- (/ (cdr pair) (+ (frame-char-height frame) spacing)) - (if (null (with-current-buffer (window-buffer window) - header-line-format)) - 0 1)))))))) + (/ (cdr pair) (+ (frame-char-height frame) spacing)))))))) (defun posn-actual-col-row (position) "Return the actual column and row in POSITION, measured in characters. diff --git a/src/ChangeLog b/src/ChangeLog index 5e3ec8aa597..5f00b654261 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2014-09-02 Eli Zaretskii + + * dispnew.c (buffer_posn_from_coords): Fix an off-by-one error in + the reported row in the case of a window with a header line, by + improving on the fix committed in 2011-10-08T10:58:50Z!eliz@gnu.org + eliz@gnu.org-20111008105850-ht4tvsayohvr1kjc. (Bug#18384) + 2014-09-02 Paul Eggert * eval.c (internal_lisp_condition_case): Don't overrun the stack diff --git a/src/dispnew.c b/src/dispnew.c index e6ab5bf1e9c..9725068c72b 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -5107,7 +5107,7 @@ buffer_posn_from_coords (struct window *w, int *x, int *y, struct display_pos *p #ifdef HAVE_WINDOW_SYSTEM struct image *img = 0; #endif - int x0, x1, to_x; + int x0, x1, to_x, it_vpos; void *itdata = NULL; /* We used to set current_buffer directly here, but that does the @@ -5116,11 +5116,6 @@ buffer_posn_from_coords (struct window *w, int *x, int *y, struct display_pos *p itdata = bidi_shelve_cache (); CLIP_TEXT_POS_FROM_MARKER (startp, w->start); start_display (&it, w, startp); - /* start_display takes into account the header-line row, but IT's - vpos still counts from the glyph row that includes the window's - start position. Adjust for a possible header-line row. */ - it.vpos += WINDOW_WANTS_HEADER_LINE_P (w); - x0 = *x; /* First, move to the beginning of the row corresponding to *Y. We @@ -5190,8 +5185,13 @@ buffer_posn_from_coords (struct window *w, int *x, int *y, struct display_pos *p } #endif - if (it.vpos < w->current_matrix->nrows - && (row = MATRIX_ROW (w->current_matrix, it.vpos), + /* IT's vpos counts from the glyph row that includes the window's + start position, i.e. it excludes the header-line row, but + MATRIX_ROW includes the header-line row. Adjust for a possible + header-line row. */ + it_vpos = it.vpos + WINDOW_WANTS_MODELINE_P (w); + if (it_vpos < w->current_matrix->nrows + && (row = MATRIX_ROW (w->current_matrix, it_vpos), row->enabled_p)) { if (it.hpos < row->used[TEXT_AREA]) -- 2.39.5