From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.bugs Subject: bug#35536: 27.0.50; Expose buffer's marker list to Elisp Date: Thu, 02 May 2019 16:44:52 +0100 Message-ID: <87lfzo274b.fsf@tcd.ie> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="101346"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Mauro Aranda , Stefan Monnier To: 35536@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu May 02 17:46:24 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hMDuh-000Q83-04 for geb-bug-gnu-emacs@m.gmane.org; Thu, 02 May 2019 17:46:23 +0200 Original-Received: from localhost ([127.0.0.1]:53382 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMDuf-0005kf-UE for geb-bug-gnu-emacs@m.gmane.org; Thu, 02 May 2019 11:46:21 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:36136) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMDuT-0005hz-00 for bug-gnu-emacs@gnu.org; Thu, 02 May 2019 11:46:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMDuQ-0001Nr-SI for bug-gnu-emacs@gnu.org; Thu, 02 May 2019 11:46:08 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33232) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hMDuQ-0001Nn-Nq for bug-gnu-emacs@gnu.org; Thu, 02 May 2019 11:46:06 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hMDuM-0006so-0f; Thu, 02 May 2019 11:46:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: rudalics@gmx.at, maurooaranda@gmail.com, monnier@iro.umontreal.ca, bug-gnu-emacs@gnu.org Resent-Date: Thu, 02 May 2019 15:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 35536 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: martin rudalics , Mauro Aranda , Stefan Monnier Original-Received: via spool by submit@debbugs.gnu.org id=B.155681191426390 (code B ref -1); Thu, 02 May 2019 15:46:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 2 May 2019 15:45:14 +0000 Original-Received: from localhost ([127.0.0.1]:46770 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMDtZ-0006rZ-Sn for submit@debbugs.gnu.org; Thu, 02 May 2019 11:45:14 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:49785) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMDtX-0006rG-Ek for submit@debbugs.gnu.org; Thu, 02 May 2019 11:45:12 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:47678) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hMDtS-0000w9-8g for submit@debbugs.gnu.org; Thu, 02 May 2019 11:45:06 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:35931) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMDtQ-0005Uq-DJ for bug-gnu-emacs@gnu.org; Thu, 02 May 2019 11:45:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMDtO-0000vI-IB for bug-gnu-emacs@gnu.org; Thu, 02 May 2019 11:45:04 -0400 Original-Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]:39697) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hMDtN-0000uv-Mo for bug-gnu-emacs@gnu.org; Thu, 02 May 2019 11:45:02 -0400 Original-Received: by mail-ed1-x541.google.com with SMTP id e24so2536729edq.6 for ; Thu, 02 May 2019 08:45:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:user-agent:mime-version; bh=dZ1Fvg7Ch0aUJiPFvis44TXCJKFNMk4UfQ5zNdPMxZE=; b=vbYOsrL2fSBmGcswDWEQvVhnNLXQAMVRvB0srhsFNPM6lVtPl6cJiBqQD71XqQVZL2 +TRhmLsuRV022ZOJWLvyO2lYswc49p9IXxrQ5nKKfORvNhDJT3lJmJvAOf8tRNBmZgeR U6NobTy7/7zQcs9YVrXYDI4uRIiAzxfZo9D5ybwnhxEEpE90CxMLVkWSnGb/6YYLY3Mm YTjnjufynA0hTWR7O2YRhJkcE5Y5/7wdYPuDAA4BIcb1eyPueYsBQuYqs1NeDNu1FGNY NmwfaYiKvKipGgMKzjOJpqin18TyrDwyYOVcwBNDF1VIBkDCeqaYYOiVplpw4sUrnBYg iRhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:user-agent :mime-version; bh=dZ1Fvg7Ch0aUJiPFvis44TXCJKFNMk4UfQ5zNdPMxZE=; b=fssi1UlWUOQH203j+NRaBG3AddCAAku5V9UNuxbiz1h0FbAs+n3lokLkaQ/YXrhLJn 9pUqLfosKL/x+SGKi5xSfnkfk8J9A9LSNzAGNU/UySWod3d+IOtMJaDv/ZdmJfpKER9I aS4uzj7qDpCqjN4P4mr/5yWK5LLw/zZDvWGnRcp6JEfi0+Ajvkp2iSxGZr0JMrHCqIgS kjK62MuyWEsPqFNu6hd82kuo9M4qVifnnkPg1E5Iv+jzOAOq3AWU+q+9KyU4Uyv6venJ YJRN23ILv6xgUpbbqM1iXkkNi4n6sgKcTz1d+BjrQU6mQjPnSuXVhWUO0jCEYG6REqax 06Zg== X-Gm-Message-State: APjAAAWQ84ba5/WhVZwYHOKMdSiAi1+MJ4CDL5RJHpDwbjs6TdFfs93r 3ZY8qd+zeFA0o7ZD5/AQ6UtIldaLWSI= X-Google-Smtp-Source: APXvYqxv9FKfwVYCPOQs2VlzW5mKbOT84V/VykCngmbDwaxEcnKyXFp53J+Tz+HxjawYLcFV6YoHDQ== X-Received: by 2002:aa7:c919:: with SMTP id b25mr3073926edt.274.1556811899122; Thu, 02 May 2019 08:44:59 -0700 (PDT) Original-Received: from localhost ([2a02:8084:20e2:c380:8cad:ae29:555d:852d]) by smtp.gmail.com with ESMTPSA id e4sm1871551ejm.50.2019.05.02.08.44.57 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 02 May 2019 08:44:58 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:158641 Archived-At: --=-=-= Content-Type: text/plain Severity: wishlist Tags: patch --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Add-function-marker-list.patch >From c3c864a034ceb5c43fb791721a4b5c40f4122228 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Tue, 30 Apr 2019 00:17:02 +0100 Subject: [PATCH] Add function marker-list Suggested by Martin Rudalics in: https://debbugs.gnu.org/18#47 * doc/lispref/markers.texi (Marker Information): Rename from 'Information from Markers'. All references changed. Document marker-list. * etc/NEWS (Changes in Emacs 27.1): Announce marker-list. * src/data.c (syms_of_data): Define Flss symbol for passing to Fsort. * src/marker.c (Fcopy_marker): Fix indentation. (Fbuffer_has_markers_at): Coerce argument to a fixnum before passing it to XFIXNUM. (Fmarker_list): New function for listing markers in a given region. (syms_of_marker): Define subr Smarker_list. * test/src/marker-tests.el (marker-set-window-start-from-other-buffer): Simplify. (marker-list, marker-list-buffer-change): New tests. --- doc/lispref/elisp.texi | 2 +- doc/lispref/markers.texi | 22 +++++++++++------- etc/NEWS | 5 ++++ src/data.c | 1 + src/marker.c | 40 ++++++++++++++++++++++++++------ test/src/marker-tests.el | 50 ++++++++++++++++++++++++++++++++++------ 6 files changed, 97 insertions(+), 23 deletions(-) diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi index e18759654d..67c3e860aa 100644 --- a/doc/lispref/elisp.texi +++ b/doc/lispref/elisp.texi @@ -1168,7 +1168,7 @@ Top * Overview of Markers:: The components of a marker, and how it relocates. * Predicates on Markers:: Testing whether an object is a marker. * Creating Markers:: Making empty markers or markers at certain places. -* Information from Markers::Finding the marker's buffer or character position. +* Marker Information:: Finding the marker's buffer or character position. * Marker Insertion Types:: Two ways a marker can relocate when you insert where it points. * Moving Markers:: Moving the marker to a new buffer or position. diff --git a/doc/lispref/markers.texi b/doc/lispref/markers.texi index 27fe1414f0..d18cad2eb8 100644 --- a/doc/lispref/markers.texi +++ b/doc/lispref/markers.texi @@ -16,7 +16,7 @@ Markers * Overview of Markers:: The components of a marker, and how it relocates. * Predicates on Markers:: Testing whether an object is a marker. * Creating Markers:: Making empty markers or markers at certain places. -* Information from Markers:: Finding the marker's buffer or character position. +* Marker Information:: Finding the marker's buffer or character position. * Marker Insertion Types:: Two ways a marker can relocate when you insert where it points. * Moving Markers:: Moving the marker to a new buffer or position. @@ -271,12 +271,12 @@ Creating Markers @end group @end example -@node Information from Markers -@section Information from Markers +@node Marker Information +@section Marker Information @cindex marker information - This section describes the functions for accessing the components of a -marker object. +Several functions return information about markers. The next two +functions access components of a marker object. @defun marker-position marker This function returns the position that @var{marker} points to, or @@ -287,8 +287,6 @@ Information from Markers This function returns the buffer that @var{marker} points into, or @code{nil} if it points nowhere. -@c FIXME: The 'buffer' argument of 'set-marker' already defaults to -@c the current buffer, why use '(current-buffer)' explicitly here? @example @group (setq m (make-marker)) @@ -304,7 +302,7 @@ Information from Markers @end group @group -(set-marker m 3770 (current-buffer)) +(set-marker m 3770) @result{} # @end group @group @@ -318,6 +316,14 @@ Information from Markers @end example @end defun +@defun marker-list &optional beg end +This function returns an ordered list of the markers in the accessible +range of the current buffer. If @var{beg} is non-@code{nil}, only +markers pointing at that position are included. If @var{end} is also +non-@code{nil}, all markers in the region @var{beg} through @var{end} +are included. +@end defun + @node Marker Insertion Types @section Marker Insertion Types diff --git a/etc/NEWS b/etc/NEWS index 9e3559d27e..dc5923a293 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -340,6 +340,11 @@ longer. ** Multicolor fonts such as "Noto Color Emoji" can be displayed on Emacs configured with Cairo drawing and linked with cairo >= 1.16.0. ++++ +** New function 'marker-list'. +This function returns a list of markers in the current buffer within a +given region. + * Editing Changes in Emacs 27.1 diff --git a/src/data.c b/src/data.c index 476d28eadb..0bf841e928 100644 --- a/src/data.c +++ b/src/data.c @@ -3852,6 +3852,7 @@ syms_of_data (void) DEFSYM (Qmany, "many"); DEFSYM (Qcdr, "cdr"); + DEFSYM (Qlss, "<"); error_tail = pure_cons (Qerror, Qnil); diff --git a/src/marker.c b/src/marker.c index b58051a8c2..d132a43c09 100644 --- a/src/marker.c +++ b/src/marker.c @@ -712,7 +712,8 @@ see `marker-insertion-type'. */) register Lisp_Object new; if (!NILP (marker)) - CHECK_TYPE (FIXNUMP (marker) || MARKERP (marker), Qinteger_or_marker_p, marker); + CHECK_TYPE (FIXNUMP (marker) || MARKERP (marker), + Qinteger_or_marker_p, marker); new = Fmake_marker (); Fset_marker (new, marker, @@ -749,18 +750,42 @@ DEFUN ("buffer-has-markers-at", Fbuffer_has_markers_at, Sbuffer_has_markers_at, doc: /* Return t if there are markers pointing at POSITION in the current buffer. */) (Lisp_Object position) { - register struct Lisp_Marker *tail; - register ptrdiff_t charpos; + CHECK_FIXNUM_COERCE_MARKER (position); + ptrdiff_t charpos = clip_to_bounds (BEG, XFIXNUM (position), Z); - charpos = clip_to_bounds (BEG, XFIXNUM (position), Z); - - for (tail = BUF_MARKERS (current_buffer); tail; tail = tail->next) - if (tail->charpos == charpos) + for (struct Lisp_Marker *m = BUF_MARKERS (current_buffer); m; m = m->next) + if (m->charpos == charpos) return Qt; return Qnil; } +DEFUN ("marker-list", Fmarker_list, Smarker_list, 0, 2, 0, + doc: /* Return a list of markers in the accessible range of the buffer. +If BEG is non-nil, include only markers pointing at that position. +If END is also non-nil, include all markers in the region BEG +through END. */) + (Lisp_Object beg, Lisp_Object end) +{ + ptrdiff_t b, e; + if (NILP (beg)) + b = BEGV, e = ZV; + else + { + validate_region (&beg, NILP (end) ? &beg : &end); + b = XFIXNAT (beg); + e = NILP (end) ? b : XFIXNAT (end); + } + + Lisp_Object markers = Qnil; + + for (struct Lisp_Marker *m = BUF_MARKERS (current_buffer); m; m = m->next) + if (b <= m->charpos && m->charpos <= e) + markers = Fcons (make_lisp_ptr (m, Lisp_Vectorlike), markers); + + return Fsort (markers, Qlss); +} + #ifdef MARKER_DEBUG /* For debugging -- count the markers in buffer BUF. */ @@ -807,4 +832,5 @@ syms_of_marker (void) defsubr (&Smarker_insertion_type); defsubr (&Sset_marker_insertion_type); defsubr (&Sbuffer_has_markers_at); + defsubr (&Smarker_list); } diff --git a/test/src/marker-tests.el b/test/src/marker-tests.el index 79e298d8c2..cbafabb556 100644 --- a/test/src/marker-tests.el +++ b/test/src/marker-tests.el @@ -29,16 +29,15 @@ (ert-deftest marker-set-window-start-from-other-buffer () "`set-window-start' from other buffer's marker." (let ((text-quoting-style 'curve)) - (describe-function 'describe-function)) - (let* ((help (get-buffer "*Help*")) - (marker (with-current-buffer help - (copy-marker (point-max))))) + (describe-function #'describe-function)) + (let ((marker (with-current-buffer "*Help*" + (copy-marker (point-max))))) (should (set-window-start (selected-window) marker)))) (ert-deftest marker-set-window-point-from-other-buffer () "`set-window-point' from another buffer's marker." (let ((text-quoting-style 'curve)) - (describe-function 'describe-function)) + (describe-function #'describe-function)) (let* ((help (get-buffer "*Help*")) (marker (with-current-buffer help (copy-marker (point-max))))) @@ -48,13 +47,50 @@ (ert-deftest marker-goto-char-from-other-buffer () "`goto-char' from another buffer's marker." (let ((text-quoting-style 'curve)) - (describe-function 'describe-function)) + (describe-function #'describe-function)) (let ((marker-1 (make-marker)) (marker-2 (make-marker))) - (describe-function 'describe-function) + (describe-function #'describe-function) (with-current-buffer "*Help*" (set-marker marker-1 (point-max))) (set-marker marker-2 marker-1) (should (goto-char marker-2)))) +(ert-deftest marker-list () + "Test `marker-list' behavior." + (with-temp-buffer + ;; No markers created yet. + (should-not (marker-list)) + (insert "first\nsecond\n") + (forward-line -1) + (let ((markers (list (point-min-marker) (point-max-marker)))) + ;; Check marker arguments. + (should (equal (apply #'marker-list markers) markers)) + (save-restriction + (narrow-to-region (point) (line-end-position)) + ;; Check accessible range of buffer. + (should-not (marker-list)) + ;; Check invalid region. + (should-error (apply #'marker-list markers) + :type 'args-out-of-range))) + ;; Check single position and that mark is included. + (let ((marker (set-marker (mark-marker) (point)))) + (should (equal (marker-list (point)) (list marker)))) + ;; Check that unchained markers are not included. + (dolist (marker (marker-list)) + (set-marker marker nil)) + (should-not (marker-list)))) + +(ert-deftest marker-list-buffer-change () + "Test `marker-list' behavior across buffer changes." + (with-temp-buffer + (let ((marker (point-marker)) + (markers (marker-list))) + (with-temp-buffer + (set-marker marker (point)) + (should (equal (marker-list) (list marker))) + (should (equal (mapcar #'marker-buffer markers) + (list (current-buffer))))) + (should-not (marker-list))))) + ;;; marker-tests.el ends here. -- 2.20.1 --=-=-= Content-Type: text/plain The question of listing a buffer's markers has been raised before: https://debbugs.gnu.org/18#47 https://lists.gnu.org/archive/html/help-gnu-emacs/2016-06/msg00050.html https://lists.gnu.org/archive/html/emacs-devel/2007-04/msg01391.html I attach a patch implementing this based on BUF_MARKERS, as per Martin's suggestion. Any reasons not to expose such a function? Thanks, -- Basil In GNU Emacs 27.0.50 (build 4, x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars) of 2019-04-30 built on thunk Repository revision: 910d170771ac74ab76d6dcb2dda3f3167e01b705 Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12003000 System Description: Debian GNU/Linux buster/sid --=-=-=--