diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2019-01-27 15:49:53 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2019-01-27 15:52:06 -0800 |
commit | cc1c46e4122a08657a7c75495115d1c60efb1b31 (patch) | |
tree | 263f419e5f70ab9dceaa15093339623bf3513e64 /src/cmds.c | |
parent | 6c2ee11d8f27cc39f852b69a49056ba76ac6bee9 (diff) | |
download | emacs-cc1c46e4122a08657a7c75495115d1c60efb1b31.tar.gz |
forward-line now works with bignums
* src/cmds.c (Fforward_line): Support bignum arg.
(scan_newline): Return void since no caller was using the
return value.
* src/search.c (find_newline, scan_newline_from_point)
(find_newline1): Return the number of newlines counted, not
the count shortage, so that the return value always fits in
ptrdiff_t even if the original count was a bignum. All
callers changed.
* test/src/cmds-tests.el (forward-line-with-bignum): New test.
Diffstat (limited to 'src/cmds.c')
-rw-r--r-- | src/cmds.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/cmds.c b/src/cmds.c index 1f81b9986a7..239e3be5c07 100644 --- a/src/cmds.c +++ b/src/cmds.c @@ -121,28 +121,36 @@ it as a line moved across, even though there is no next line to go to its beginning. */) (Lisp_Object n) { - ptrdiff_t opoint = PT, pos, pos_byte, shortage, count; + ptrdiff_t opoint = PT, pos, pos_byte, count; + bool excessive = false; if (NILP (n)) count = 1; else { - CHECK_FIXNUM (n); - count = XFIXNUM (n); + CHECK_INTEGER (n); + if (FIXNUMP (n) + && -BUF_BYTES_MAX <= XFIXNUM (n) && XFIXNUM (n) <= BUF_BYTES_MAX) + count = XFIXNUM (n); + else + { + count = !NILP (Fnatnump (n)) ? BUF_BYTES_MAX : -BUF_BYTES_MAX; + excessive = true; + } } - shortage = scan_newline_from_point (count, &pos, &pos_byte); + ptrdiff_t counted = scan_newline_from_point (count, &pos, &pos_byte); SET_PT_BOTH (pos, pos_byte); - if (shortage > 0 - && (count <= 0 - || (ZV > BEGV - && PT != opoint - && (FETCH_BYTE (PT_BYTE - 1) != '\n')))) - shortage--; - - return make_fixnum (count <= 0 ? - shortage : shortage); + ptrdiff_t shortage = count - (count <= 0) - counted; + if (shortage != 0) + shortage -= (count <= 0 ? -1 + : (BEGV < ZV && PT != opoint + && FETCH_BYTE (PT_BYTE - 1) != '\n')); + return (excessive + ? CALLN (Fplus, make_fixnum (shortage - count), n) + : make_fixnum (shortage)); } DEFUN ("beginning-of-line", Fbeginning_of_line, Sbeginning_of_line, 0, 1, "^p", |