* Emacs master commit: "Add current-line in simple.el" - Wrong commit log?
@ 2017-06-19 12:12 Kaushal Modi
2017-06-19 12:41 ` Nicolas Petton
2017-06-19 12:42 ` Nicolas Petton
0 siblings, 2 replies; 8+ messages in thread
From: Kaushal Modi @ 2017-06-19 12:12 UTC (permalink / raw)
To: Emacs developers, damien, Nicolas Petton
[-- Attachment #1: Type: text/plain, Size: 356 bytes --]
The commit heading and body refer to a new function called current-line.
But the commit is basically adding a new optional arg absolute-p to
line-number-at-pos; I do not see any reference to a new function
current-line in the actual commit.
http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=ae98cdf9431604d0f722f1db217ca06debfbb7b6
--
Kaushal Modi
[-- Attachment #2: Type: text/html, Size: 624 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Emacs master commit: "Add current-line in simple.el" - Wrong commit log?
2017-06-19 12:12 Emacs master commit: "Add current-line in simple.el" - Wrong commit log? Kaushal Modi
@ 2017-06-19 12:41 ` Nicolas Petton
2017-06-19 13:58 ` Kaushal Modi
2017-06-19 12:42 ` Nicolas Petton
1 sibling, 1 reply; 8+ messages in thread
From: Nicolas Petton @ 2017-06-19 12:41 UTC (permalink / raw)
To: Kaushal Modi, Emacs developers, damien
[-- Attachment #1: Type: text/plain, Size: 422 bytes --]
Kaushal Modi <kaushal.modi@gmail.com> writes:
> The commit heading and body refer to a new function called current-line.
>
> But the commit is basically adding a new optional arg absolute-p to
> line-number-at-pos; I do not see any reference to a new function
> current-line in the actual commit.
Indeed, the patch got revised a few times, and I forgot to double-check
the commit message when applying it.
Cheers,
Nico
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Emacs master commit: "Add current-line in simple.el" - Wrong commit log?
2017-06-19 12:12 Emacs master commit: "Add current-line in simple.el" - Wrong commit log? Kaushal Modi
2017-06-19 12:41 ` Nicolas Petton
@ 2017-06-19 12:42 ` Nicolas Petton
2017-06-24 7:35 ` Damien Cassou
1 sibling, 1 reply; 8+ messages in thread
From: Nicolas Petton @ 2017-06-19 12:42 UTC (permalink / raw)
To: Kaushal Modi, Emacs developers, damien
[-- Attachment #1: Type: text/plain, Size: 377 bytes --]
Kaushal Modi <kaushal.modi@gmail.com> writes:
> The commit heading and body refer to a new function called current-line.
>
> But the commit is basically adding a new optional arg absolute-p to
> line-number-at-pos; I do not see any reference to a new function
> current-line in the actual commit.
I'll revert the commit. Damien, can you provide another patch?
Cheers,
Nico
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Emacs master commit: "Add current-line in simple.el" - Wrong commit log?
2017-06-19 12:41 ` Nicolas Petton
@ 2017-06-19 13:58 ` Kaushal Modi
0 siblings, 0 replies; 8+ messages in thread
From: Kaushal Modi @ 2017-06-19 13:58 UTC (permalink / raw)
To: Nicolas Petton, Emacs developers, damien
[-- Attachment #1: Type: text/plain, Size: 444 bytes --]
On Mon, Jun 19, 2017 at 8:41 AM Nicolas Petton <nicolas@petton.fr> wrote:
> Indeed, the patch got revised a few times, and I forgot to double-check
> the commit message when applying it.
>
Thanks! That explains :)
Also, if the back-story of this commit is a bug report, it would be useful
to have "(Bug#NNNNN)" in the commit log.
Reference: http://git.savannah.gnu.org/cgit/emacs.git/plain/CONTRIBUTE (Search
for "Bug#").
--
Kaushal Modi
[-- Attachment #2: Type: text/html, Size: 938 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Emacs master commit: "Add current-line in simple.el" - Wrong commit log?
2017-06-19 12:42 ` Nicolas Petton
@ 2017-06-24 7:35 ` Damien Cassou
2017-06-29 12:21 ` Nicolas Petton
0 siblings, 1 reply; 8+ messages in thread
From: Damien Cassou @ 2017-06-24 7:35 UTC (permalink / raw)
To: Nicolas Petton, Kaushal Modi, Emacs developers
[-- Attachment #1: Type: text/plain, Size: 448 bytes --]
Nicolas Petton <nicolas@petton.fr> writes:
> I'll revert the commit. Damien, can you provide another patch?
Here is a new version. I took the opportunity to add a NEWS entry
and to reflect the change in the elisp manual. Please double-check
everything.
--
Damien Cassou
Företagsplatsen AB
Phone/Fax: +46 (0)8 774 63 00
Mobile: +33 (0)6 80 50 18 91
Address: Skeppsbron 26, 4tr, SE-111 30 Stockholm
Web: www.foretagsplatsen.se
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-absolute-p-optional-parameter-to-line-number-at-.patch --]
[-- Type: text/x-patch, Size: 5929 bytes --]
From c9c50d91f19de77577c95e610420ee8e9622efeb Mon Sep 17 00:00:00 2001
From: Damien Cassou <damien@cassou.me>
Date: Sun, 9 Apr 2017 12:46:57 +0200
Subject: [PATCH] Add absolute-p optional parameter to line-number-at-pos
(Bug#26417)
* lisp/simple.el (line-number-at-pos): Add a second optional
argument 'absolute-p'.
* test/list/simple-tests.el: Add tests for 'line-number-at-pos'.
---
doc/lispref/positions.texi | 11 ++++++++---
etc/NEWS | 7 +++++++
lisp/simple.el | 29 ++++++++++++++++-----------
test/lisp/simple-tests.el | 49 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 82 insertions(+), 14 deletions(-)
diff --git a/doc/lispref/positions.texi b/doc/lispref/positions.texi
index 7c30fe9..5e1e92f 100644
--- a/doc/lispref/positions.texi
+++ b/doc/lispref/positions.texi
@@ -432,11 +432,16 @@ Text Lines
in the buffer, or in the region if the region is active.
@end deffn
-@defun line-number-at-pos &optional pos
+@defun line-number-at-pos &optional pos absolute-p
@cindex line number
This function returns the line number in the current buffer
-corresponding to the buffer position @var{pos}. If @var{pos} is @code{nil}
-or omitted, the current buffer position is used.
+corresponding to the buffer position @var{pos}. If @var{pos} is
+@code{nil} or omitted, the current buffer position is used. If
+@var{absolute-p} is @code{nil}, the default, counting starts at
+@code{(point-min)}, so the value refers to the contents of the
+accessible portion of the (potentially narrowed) buffer. If
+@var{absolute-p} is non-@code{nil}, ignore any narrowing and return
+the absolute line number.
@end defun
@ignore
diff --git a/etc/NEWS b/etc/NEWS
index 78d37484..68cc686 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1187,6 +1187,13 @@ or its files before 'delete-directory' gets to them.
*** New error type 'user-search-failed' like 'search-failed' but
avoids debugger like 'user-error'.
++++
+** The function 'line-number-at-pos' now takes a second optional
+argument 'absolute-p'. If this parameter is nil, the default, this
+function keeps on returning the line number taking potential narrowing
+into account. If this parameter is non-nil, the function ignores
+narrowing and returns the absolute line number.
+
** Changes in Frame- and Window- Handling
+++
diff --git a/lisp/simple.el b/lisp/simple.el
index a5565ab..e3b7665 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1270,18 +1270,25 @@ (defun count-lines (start end)
done)))
(- (buffer-size) (forward-line (buffer-size)))))))
-(defun line-number-at-pos (&optional pos)
- "Return (narrowed) buffer line number at position POS.
+(defun line-number-at-pos (&optional pos absolute-p)
+ "Return buffer line number at position POS.
If POS is nil, use current buffer location.
-Counting starts at (point-min), so the value refers
-to the contents of the accessible portion of the buffer."
- (let ((opoint (or pos (point))) start)
- (save-excursion
- (goto-char (point-min))
- (setq start (point))
- (goto-char opoint)
- (forward-line 0)
- (1+ (count-lines start (point))))))
+
+If ABSOLUTE-P is nil, the default, counting starts
+at (point-min), so the value refers to the contents of the
+accessible portion of the (potentially narrowed) buffer. If
+ABSOLUTE-P is non-nil, ignore any narrowing and return the
+absolute line number."
+ (save-restriction
+ (when absolute-p
+ (widen))
+ (let ((opoint (or pos (point))) start)
+ (save-excursion
+ (goto-char (point-min))
+ (setq start (point))
+ (goto-char opoint)
+ (forward-line 0)
+ (1+ (count-lines start (point)))))))
(defun what-cursor-position (&optional detail)
"Print info on cursor position (on screen and within buffer).
diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el
index 180dcc0..ad7aee1 100644
--- a/test/lisp/simple-tests.el
+++ b/test/lisp/simple-tests.el
@@ -448,5 +448,54 @@ (ert-deftest eval-expression-print-format-large-int-echo ()
(call-interactively #'eval-expression)
(should (equal (current-message) "66 (#o102, #x42, ?B)"))))))
+(ert-deftest line-number-at-pos-in-widen-buffer ()
+ (let ((target-line 3))
+ (with-temp-buffer
+ (insert "a\nb\nc\nd\n")
+ (goto-char (point-min))
+ (forward-line (1- target-line))
+ (should (equal (line-number-at-pos) target-line))
+ (should (equal (line-number-at-pos nil t) target-line)))))
+
+(ert-deftest line-number-at-pos-in-narrow-buffer ()
+ (let ((target-line 3))
+ (with-temp-buffer
+ (insert "a\nb\nc\nd\n")
+ (goto-char (point-min))
+ (forward-line (1- target-line))
+ (narrow-to-region (line-beginning-position) (line-end-position))
+ (should (equal (line-number-at-pos) 1))
+ (should (equal (line-number-at-pos nil t) target-line)))))
+
+(ert-deftest line-number-at-pos-keeps-restriction ()
+ (with-temp-buffer
+ (insert "a\nb\nc\nd\n")
+ (goto-char (point-min))
+ (forward-line 2)
+ (narrow-to-region (line-beginning-position) (line-end-position))
+ (should (equal (line-number-at-pos) 1))
+ (line-number-at-pos nil t)
+ (should (equal (line-number-at-pos) 1))))
+
+(ert-deftest line-number-at-pos-keeps-point ()
+ (let (pos)
+ (with-temp-buffer
+ (insert "a\nb\nc\nd\n")
+ (goto-char (point-min))
+ (forward-line 2)
+ (setq pos (point))
+ (line-number-at-pos)
+ (line-number-at-pos nil t)
+ (should (equal pos (point))))))
+
+(ert-deftest line-number-at-pos-when-passing-point ()
+ (let (pos)
+ (with-temp-buffer
+ (insert "a\nb\nc\nd\n")
+ (should (equal (line-number-at-pos 1) 1))
+ (should (equal (line-number-at-pos 3) 2))
+ (should (equal (line-number-at-pos 5) 3))
+ (should (equal (line-number-at-pos 7) 4)))))
+
(provide 'simple-test)
;;; simple-test.el ends here
--
2.9.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: Emacs master commit: "Add current-line in simple.el" - Wrong commit log?
2017-06-24 7:35 ` Damien Cassou
@ 2017-06-29 12:21 ` Nicolas Petton
2017-07-03 7:03 ` Damien Cassou
0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Petton @ 2017-06-29 12:21 UTC (permalink / raw)
To: Damien Cassou, Emacs developers
[-- Attachment #1: Type: text/plain, Size: 449 bytes --]
Damien Cassou <damien@cassou.me> writes:
> Here is a new version. I took the opportunity to add a NEWS entry
> and to reflect the change in the elisp manual.
Great, thanks!
> -(defun line-number-at-pos (&optional pos)
> - "Return (narrowed) buffer line number at position POS.
> +(defun line-number-at-pos (&optional pos absolute-p)
Why not simply `absolute' instead of `absolute-p'. It's not a predicate,
is it?
Cheers,
Nico
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Emacs master commit: "Add current-line in simple.el" - Wrong commit log?
2017-06-29 12:21 ` Nicolas Petton
@ 2017-07-03 7:03 ` Damien Cassou
2017-07-03 12:45 ` Nicolas Petton
0 siblings, 1 reply; 8+ messages in thread
From: Damien Cassou @ 2017-07-03 7:03 UTC (permalink / raw)
To: Nicolas Petton, Emacs developers
[-- Attachment #1: Type: text/plain, Size: 302 bytes --]
Nicolas Petton <nicolas@petton.fr> writes:
> Why not simply `absolute' instead of `absolute-p'. It's not a
> predicate, is it?
fixed.
--
Damien Cassou
http://damiencassou.seasidehosting.st
"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-absolute-optional-parameter-to-line-number-at-.patch --]
[-- Type: text/x-patch, Size: 5909 bytes --]
From c9c50d91f19de77577c95e610420ee8e9622efeb Mon Sep 17 00:00:00 2001
From: Damien Cassou <damien@cassou.me>
Date: Sun, 9 Apr 2017 12:46:57 +0200
Subject: [PATCH] Add absolute optional parameter to line-number-at-pos
(Bug#26417)
* lisp/simple.el (line-number-at-pos): Add a second optional
argument 'absolute'.
* test/list/simple-tests.el: Add tests for 'line-number-at-pos'.
---
doc/lispref/positions.texi | 11 ++++++++---
etc/NEWS | 7 +++++++
lisp/simple.el | 29 ++++++++++++++++-----------
test/lisp/simple-tests.el | 49 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 82 insertions(+), 14 deletions(-)
diff --git a/doc/lispref/positions.texi b/doc/lispref/positions.texi
index 7c30fe9..5e1e92f 100644
--- a/doc/lispref/positions.texi
+++ b/doc/lispref/positions.texi
@@ -432,11 +432,16 @@ Text Lines
in the buffer, or in the region if the region is active.
@end deffn
-@defun line-number-at-pos &optional pos
+@defun line-number-at-pos &optional pos absolute
@cindex line number
This function returns the line number in the current buffer
-corresponding to the buffer position @var{pos}. If @var{pos} is @code{nil}
-or omitted, the current buffer position is used.
+corresponding to the buffer position @var{pos}. If @var{pos} is
+@code{nil} or omitted, the current buffer position is used. If
+@var{absolute} is @code{nil}, the default, counting starts at
+@code{(point-min)}, so the value refers to the contents of the
+accessible portion of the (potentially narrowed) buffer. If
+@var{absolute} is non-@code{nil}, ignore any narrowing and return
+the absolute line number.
@end defun
@ignore
diff --git a/etc/NEWS b/etc/NEWS
index 78d37484..68cc686 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1187,6 +1187,13 @@ or its files before 'delete-directory' gets to them.
*** New error type 'user-search-failed' like 'search-failed' but
avoids debugger like 'user-error'.
++++
+** The function 'line-number-at-pos' now takes a second optional
+argument 'absolute'. If this parameter is nil, the default, this
+function keeps on returning the line number taking potential narrowing
+into account. If this parameter is non-nil, the function ignores
+narrowing and returns the absolute line number.
+
** Changes in Frame- and Window- Handling
+++
diff --git a/lisp/simple.el b/lisp/simple.el
index a5565ab..e3b7665 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1270,18 +1270,25 @@ (defun count-lines (start end)
done)))
(- (buffer-size) (forward-line (buffer-size)))))))
-(defun line-number-at-pos (&optional pos)
- "Return (narrowed) buffer line number at position POS.
+(defun line-number-at-pos (&optional pos absolute)
+ "Return buffer line number at position POS.
If POS is nil, use current buffer location.
-Counting starts at (point-min), so the value refers
-to the contents of the accessible portion of the buffer."
- (let ((opoint (or pos (point))) start)
- (save-excursion
- (goto-char (point-min))
- (setq start (point))
- (goto-char opoint)
- (forward-line 0)
- (1+ (count-lines start (point))))))
+
+If ABSOLUTE is nil, the default, counting starts
+at (point-min), so the value refers to the contents of the
+accessible portion of the (potentially narrowed) buffer. If
+ABSOLUTE is non-nil, ignore any narrowing and return the
+absolute line number."
+ (save-restriction
+ (when absolute
+ (widen))
+ (let ((opoint (or pos (point))) start)
+ (save-excursion
+ (goto-char (point-min))
+ (setq start (point))
+ (goto-char opoint)
+ (forward-line 0)
+ (1+ (count-lines start (point)))))))
(defun what-cursor-position (&optional detail)
"Print info on cursor position (on screen and within buffer).
diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el
index 180dcc0..ad7aee1 100644
--- a/test/lisp/simple-tests.el
+++ b/test/lisp/simple-tests.el
@@ -448,5 +448,54 @@ (ert-deftest eval-expression-print-format-large-int-echo ()
(call-interactively #'eval-expression)
(should (equal (current-message) "66 (#o102, #x42, ?B)"))))))
+(ert-deftest line-number-at-pos-in-widen-buffer ()
+ (let ((target-line 3))
+ (with-temp-buffer
+ (insert "a\nb\nc\nd\n")
+ (goto-char (point-min))
+ (forward-line (1- target-line))
+ (should (equal (line-number-at-pos) target-line))
+ (should (equal (line-number-at-pos nil t) target-line)))))
+
+(ert-deftest line-number-at-pos-in-narrow-buffer ()
+ (let ((target-line 3))
+ (with-temp-buffer
+ (insert "a\nb\nc\nd\n")
+ (goto-char (point-min))
+ (forward-line (1- target-line))
+ (narrow-to-region (line-beginning-position) (line-end-position))
+ (should (equal (line-number-at-pos) 1))
+ (should (equal (line-number-at-pos nil t) target-line)))))
+
+(ert-deftest line-number-at-pos-keeps-restriction ()
+ (with-temp-buffer
+ (insert "a\nb\nc\nd\n")
+ (goto-char (point-min))
+ (forward-line 2)
+ (narrow-to-region (line-beginning-position) (line-end-position))
+ (should (equal (line-number-at-pos) 1))
+ (line-number-at-pos nil t)
+ (should (equal (line-number-at-pos) 1))))
+
+(ert-deftest line-number-at-pos-keeps-point ()
+ (let (pos)
+ (with-temp-buffer
+ (insert "a\nb\nc\nd\n")
+ (goto-char (point-min))
+ (forward-line 2)
+ (setq pos (point))
+ (line-number-at-pos)
+ (line-number-at-pos nil t)
+ (should (equal pos (point))))))
+
+(ert-deftest line-number-at-pos-when-passing-point ()
+ (let (pos)
+ (with-temp-buffer
+ (insert "a\nb\nc\nd\n")
+ (should (equal (line-number-at-pos 1) 1))
+ (should (equal (line-number-at-pos 3) 2))
+ (should (equal (line-number-at-pos 5) 3))
+ (should (equal (line-number-at-pos 7) 4)))))
+
(provide 'simple-test)
;;; simple-test.el ends here
--
2.9.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: Emacs master commit: "Add current-line in simple.el" - Wrong commit log?
2017-07-03 7:03 ` Damien Cassou
@ 2017-07-03 12:45 ` Nicolas Petton
0 siblings, 0 replies; 8+ messages in thread
From: Nicolas Petton @ 2017-07-03 12:45 UTC (permalink / raw)
To: Damien Cassou, Emacs developers
[-- Attachment #1: Type: text/plain, Size: 254 bytes --]
Damien Cassou <damien@cassou.me> writes:
> Nicolas Petton <nicolas@petton.fr> writes:
>> Why not simply `absolute' instead of `absolute-p'. It's not a
>> predicate, is it?
>
> fixed.
Thanks, I installed you patch in master.
Cheers,
Nico
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-07-03 12:45 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-19 12:12 Emacs master commit: "Add current-line in simple.el" - Wrong commit log? Kaushal Modi
2017-06-19 12:41 ` Nicolas Petton
2017-06-19 13:58 ` Kaushal Modi
2017-06-19 12:42 ` Nicolas Petton
2017-06-24 7:35 ` Damien Cassou
2017-06-29 12:21 ` Nicolas Petton
2017-07-03 7:03 ` Damien Cassou
2017-07-03 12:45 ` Nicolas Petton
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.