]> code.delx.au - gnu-emacs/blobdiff - src/indent.c
* test/lisp/help-fns-tests.el: Add several tests for 'describe-function'.
[gnu-emacs] / src / indent.c
index 584f2179bc5ce1c0fcb78aa2997858b163606168..bc59239f20fb8b37e03fda75a265a4af3959cba3 100644 (file)
@@ -1,13 +1,13 @@
 /* Indentation functions.
-   Copyright (C) 1985-1988, 1993-1995, 1998, 2000-2015 Free Software
+   Copyright (C) 1985-1988, 1993-1995, 1998, 2000-2016 Free Software
    Foundation, Inc.
 
 This file is part of GNU Emacs.
 
 GNU Emacs is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -26,10 +26,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "category.h"
 #include "composite.h"
 #include "indent.h"
-#include "keyboard.h"
 #include "frame.h"
 #include "window.h"
-#include "termchar.h"
 #include "disptab.h"
 #include "intervals.h"
 #include "dispextern.h"
@@ -1997,7 +1995,7 @@ whether or not it is currently displayed in some window.  */)
   struct text_pos pt;
   struct window *w;
   Lisp_Object old_buffer;
-  EMACS_INT old_charpos IF_LINT (= 0), old_bytepos IF_LINT (= 0);
+  EMACS_INT old_charpos UNINIT, old_bytepos UNINIT;
   Lisp_Object lcols;
   void *itdata = NULL;
 
@@ -2038,8 +2036,8 @@ whether or not it is currently displayed in some window.  */)
       bool disp_string_at_start_p = 0;
       ptrdiff_t nlines = XINT (lines);
       int vpos_init = 0;
-      double start_col;
-      int start_x IF_LINT (= 0);
+      double start_col UNINIT;
+      int start_x UNINIT;
       int to_x = -1;
 
       bool start_x_given = !NILP (cur_col);
@@ -2132,6 +2130,15 @@ whether or not it is currently displayed in some window.  */)
              && it.method == GET_FROM_BUFFER
              && it.c == '\n')
            it_overshoot_count = 1;
+         else if (it_overshoot_count == 1 && it.vpos == 0
+                  && it.current_x < it.last_visible_x)
+           {
+             /* If we came to the same screen line as the one where
+                we started, we didn't overshoot the line, and won't
+                need to backtrack after all.  This happens, for
+                example, when PT is in the middle of a composition.  */
+             it_overshoot_count = 0;
+           }
          else if (disp_string_at_start_p && it.vpos > 0)
            {
              /* This is the case of a display string that spans
@@ -2140,6 +2147,11 @@ whether or not it is currently displayed in some window.  */)
                 screen lines we need to backtrack.  */
              it_overshoot_count = it.vpos;
            }
+         /* We will overshoot if lines are truncated and point lies
+            beyond the right margin of the window.  */
+         if (it.line_wrap == TRUNCATE && it.current_x >= it.last_visible_x
+             && it_overshoot_count == 0)
+           it_overshoot_count = 1;
          if (it_overshoot_count > 0)
            move_it_by_lines (&it, -it_overshoot_count);
 
@@ -2166,6 +2178,7 @@ whether or not it is currently displayed in some window.  */)
       if (nlines <= 0)
        {
          it.vpos = vpos_init;
+         it.current_y = 0;
          /* Do this even if LINES is 0, so that we move back to the
             beginning of the current line as we ought.  */
          if ((nlines < 0 && IT_CHARPOS (it) > 0)
@@ -2175,6 +2188,7 @@ whether or not it is currently displayed in some window.  */)
       else if (overshoot_handled)
        {
          it.vpos = vpos_init;
+         it.current_y = 0;
          move_it_by_lines (&it, min (PTRDIFF_MAX, nlines));
        }
       else
@@ -2188,6 +2202,7 @@ whether or not it is currently displayed in some window.  */)
              while (IT_CHARPOS (it) <= it_start)
                {
                  it.vpos = 0;
+                 it.current_y = 0;
                  move_it_by_lines (&it, 1);
                }
              if (nlines > 1)
@@ -2196,6 +2211,7 @@ whether or not it is currently displayed in some window.  */)
          else  /* it_start = ZV */
            {
              it.vpos = 0;
+             it.current_y = 0;
              move_it_by_lines (&it, min (PTRDIFF_MAX, nlines));
              /* We could have some display or overlay string at ZV,
                 in which case it.vpos will be nonzero now, while