[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ilist 5362c106a8 04/24: more functionalities
From: |
ELPA Syncer |
Subject: |
[elpa] externals/ilist 5362c106a8 04/24: more functionalities |
Date: |
Tue, 28 Dec 2021 16:58:13 -0500 (EST) |
branch: externals/ilist
commit 5362c106a8dbbece798f670fbc1d406d2de2dd2e
Author: JSDurand <mmemmew@gmail.com>
Commit: JSDurand <mmemmew@gmail.com>
more functionalities
* ilist.el (ilist-map-lines): Fix a bug of not executing the function
on the first line in the range.
(ilist-get-index): Get the index of the element at point.
(ilist-delete-from-list): Return a copy of the list with a sub-list
removed. The sub-list is given as a list of indices.
---
ilist.el | 44 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/ilist.el b/ilist.el
index 4223a27615..466bcfd17f 100644
--- a/ilist.el
+++ b/ilist.el
@@ -531,7 +531,6 @@ over which the function is executed."
(setq end nil)))
(save-excursion
(goto-char (cond (start) ((point-min))))
- (ilist-forward-line 1)
(let (res)
(while (and (not (ilist-boundary-buffer-p t))
(or (null end)
@@ -546,6 +545,14 @@ over which the function is executed."
(ilist-forward-line 1))
(nreverse res))))
+;;; Get index at point
+
+(defun ilist-get-index ()
+ "Return the index of the element at point.
+If point is not at an element, return nil."
+ (declare (side-effect-free t))
+ (get-text-property (point) 'ilist-index))
+
;;; marks related
;; It is possible that some user-package does not need the
@@ -815,6 +822,41 @@ to the bottom of the buffer."
(ilist-forward-group-header
(- (prefix-numeric-value arg)) rounded))
+;;; Delete from ALIST
+
+(defun ilist-delete-from-list (ls elements)
+ "Remove ELEMENTS from LS.
+ELEMENTS are indices of elements to be removed in LS.
+
+Assumes that ELEMENTS is sorted, so that the larger indices come
+later.
+
+And the indices are zero-based.
+
+This does not modify LS or ELEMENTS. It returns a copy of LS
+with ELEMENTS removed."
+ (declare (pure t) (side-effect-free t))
+ ;; REVIEW: In our case, since both LS and ELEMENTS are sorted, we
+ ;; might have a faster implementation which employs the sorted-ness
+ ;; of the arguments, but I think it is pre-mature optimisation.
+ (let* ((temp (copy-tree ls)))
+ ;; NOTE: Using `mapc' is faster than a while loop, as the manual
+ ;; says. Since `dolist' is in essence a while loop, using `mapc'
+ ;; will be faster. Of course for our purposes this is premature
+ ;; optimisation.
+ (mapc
+ (lambda (index)
+ (cond
+ ((> index 0)
+ ;; Using `setcdr' is more efficient but destructively
+ ;; modifies the list. So we used `copy-tree' to prevent the
+ ;; destructions.
+ (setcdr (nthcdr (1- index) temp)
+ (nthcdr (1+ index) temp)))
+ ((setq temp (cdr temp)))))
+ (reverse elements))
+ temp))
+
;;; major mode
;; This major mode is the basis that should be derived by
- [elpa] externals/ilist 5ba04b79bd 03/24: * ilist.el (ilist-string): Add support for sorting., (continued)
- [elpa] externals/ilist 5ba04b79bd 03/24: * ilist.el (ilist-string): Add support for sorting., ELPA Syncer, 2021/12/28
- [elpa] externals/ilist 457f0b0d87 06/24: no trailing whitespaces if demanded, ELPA Syncer, 2021/12/28
- [elpa] externals/ilist 4fb5695fe1 09/24: Add manuals and update README, ELPA Syncer, 2021/12/28
- [elpa] externals/ilist 95bcbf4b00 12/24: ilist: leave new lines when hiding groups, ELPA Syncer, 2021/12/28
- [elpa] externals/ilist 8b5d5f382f 22/24: Update docs, ELPA Syncer, 2021/12/28
- [elpa] externals/ilist f021d7d8ab 20/24: fix: account for an invisible beginning, ELPA Syncer, 2021/12/28
- [elpa] externals/ilist 282f60c93a 21/24: I forgot to byte-compile again. Silly me!, ELPA Syncer, 2021/12/28
- [elpa] externals/ilist c3f0e61360 13/24: fix missing parameter, ELPA Syncer, 2021/12/28
- [elpa] externals/ilist b2bf67c5d8 24/24: Add changelog, and update documentation, ELPA Syncer, 2021/12/28
- [elpa] externals/ilist ed18678569 05/24: new: get group and marks, ELPA Syncer, 2021/12/28
- [elpa] externals/ilist 5362c106a8 04/24: more functionalities,
ELPA Syncer <=
- [elpa] externals/ilist 347effebbe 07/24: fix the calculation of lengths of strings, ELPA Syncer, 2021/12/28
- [elpa] externals/ilist ebb207c520 08/24: Fix an ilist error, ELPA Syncer, 2021/12/28
- [elpa] externals/ilist 76f29b61bb 10/24: Minor format change, ELPA Syncer, 2021/12/28
- [elpa] externals/ilist 8c4efd3d7c 11/24: add invisible text property., ELPA Syncer, 2021/12/28
- [elpa] externals/ilist c4a48491ee 15/24: fix previous bugs caused by invisibility, ELPA Syncer, 2021/12/28
- [elpa] externals/ilist 1b16d5789d 14/24: ilist: fix some errors caused by invisibility again., ELPA Syncer, 2021/12/28
- [elpa] externals/ilist c9b456103c 16/24: Fix errors and byte-compile, ELPA Syncer, 2021/12/28
- [elpa] externals/ilist df91da4d46 17/24: ilist: try to fix a bug, ELPA Syncer, 2021/12/28
- [elpa] externals/ilist 0892dd8ffc 18/24: ilist: update the byte-compiled version, ELPA Syncer, 2021/12/28
- [elpa] externals/ilist 2279028fd5 23/24: ilist: Adding automatic filter groups, ELPA Syncer, 2021/12/28