[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/rec-mode c0ae8da 96/98: Loop fix and autoload cookie, d
From: |
Stefan Monnier |
Subject: |
[elpa] externals/rec-mode c0ae8da 96/98: Loop fix and autoload cookie, docstring clarifications |
Date: |
Thu, 12 Nov 2020 13:18:48 -0500 (EST) |
branch: externals/rec-mode
commit c0ae8da5fb670eba1d6ab34256e903d77636c0b7
Author: Antoine Kalmbach <ane@iki.fi>
Commit: Antoine Kalmbach <ane@iki.fi>
Loop fix and autoload cookie, docstring clarifications
* rec-mode.el (rec-record-descriptor): Use cl-loop to come up with something
that isn't O(n^2) by creating a list of "next" descriptors. The main loop
body
is the same: the `return' form is just a convenient way of doing `(setq
found
t)'. It's probably not "better" (in terms of readability, etc.) but cl-loop
should generate something quite efficient.
(rec-cmd-goto-next-rec): Clarify it moves to the record of the
same type.
(rec-cmd-goto-previous-rec): Ditto.
---
rec-mode.el | 40 ++++++++++++++++++++++------------------
1 file changed, 22 insertions(+), 18 deletions(-)
diff --git a/rec-mode.el b/rec-mode.el
index bdf040a..7e512f7 100644
--- a/rec-mode.el
+++ b/rec-mode.el
@@ -932,22 +932,22 @@ If the record is of no known type, return nil."
Return \"\" if no proper record descriptor is found in the file.
Return nil if the point is not on a record."
(when (rec-current-record)
- (let ((descriptors rec-buffer-descriptors)
- descriptor position found
- (i 0))
- ;; FIXME: length+nth on every iteration means O(N²) for no good reason!
- (while (and (not found)
- (< i (length descriptors)))
- (setq descriptor (nth i rec-buffer-descriptors))
- (setq position (marker-position (rec--descriptor-marker descriptor)))
- (if (and (>= (point) position)
- (or (= i (- (length rec-buffer-descriptors) 1))
- (< (point) (marker-position (nth 2 (nth (+ i 1)
rec-buffer-descriptors))))))
- (setq found t)
- (setq i (+ i 1))))
- (if found
- descriptor
- nil))))
+ (cl-loop with descriptors = rec-buffer-descriptors
+ with next-descriptors = (append (cdr descriptors) '(nil))
+ with count = (length descriptors)
+ with point = (point)
+
+ for index from 0
+ for curr in descriptors and
+ next in next-descriptors
+
+ if (and (>= point (marker-position (rec--descriptor-marker curr)))
+ (or (= index (- count 1))
+ (< point (marker-position
+ (rec--descriptor-marker
+ next)))))
+
+ return curr)))
(defun rec-summary-fields ()
"Return a list with the names of the summary fields in the current record
set."
@@ -1816,7 +1816,7 @@ Interactive version of `rec-goto-next-field'."
(rec-goto-next-field)))
(defun rec-cmd-goto-next-rec (&optional n)
- "Move to the next record.
+ "Move to the next record of the same type.
Interactive version of `rec-goto-next-rec'.
Optional argument N specifies number of records to skip."
@@ -1841,7 +1841,7 @@ Optional argument N specifies number of records to skip."
(rec-show-record)))
(defun rec-cmd-goto-previous-rec (&optional n)
- "Move to the previous record.
+ "Move to the previous record of the same type.
Interactive version of `rec-goto-previous-rec'.
Optional argument N specifies number of records to skip."
@@ -2204,6 +2204,10 @@ function returns nil."
(defvar font-lock-defaults)
(defvar add-log-current-defun-section)
+
+;;;###autoload
+(add-to-list 'auto-mode-alist '("\\.rec\\'" . rec-mode))
+
(define-derived-mode rec-mode nil "Rec"
"A major mode for editing rec files.
\\{rec-mode-map}"
- [elpa] externals/rec-mode 241e824 55/98: rec-mode: don't move the pointer after switching to edit buffer or edit type mode., (continued)
- [elpa] externals/rec-mode 241e824 55/98: rec-mode: don't move the pointer after switching to edit buffer or edit type mode., Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode d505c30 61/98: rec-mode: visiting an empty file works again., Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode 903c1dc 59/98: rec-mode: check for the validity of the contents of the buffers before going to navigation mode., Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode 979fcef 69/98: ob-rec.el: support for :groupby and :join added., Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode 34714d3 85/98: rec-mode: fix typo and run the actual hooks., Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode e1ad9fe 84/98: rec-mode: fix setq typo, Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode e4419ae 87/98: Copyright years updated to 2019., Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode 105ff13 88/98: Updated copyright years, Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode 053f28a 90/98: Lexical binding, style and compatibility fixes, Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode cd42c9f 93/98: Docstring improvements (via checkdoc), Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode c0ae8da 96/98: Loop fix and autoload cookie, docstring clarifications,
Stefan Monnier <=
- [elpa] externals/rec-mode eea5220 03/98: rec-mode: initial version of rec-cmd-compile, Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode de7c261 12/98: Copyright year updated., Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode c92fd4c 15/98: Highlight %sort, Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode fd8fdd3 10/98: auto added to rec-font-lock-keywords in rec-mode.el, Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode 011411c 28/98: rec-mode: several functions to support field types., Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode 5666b5d 27/98: rec-mode: misc fixes., Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode f7b30a1 34/98: rec-mode: folding of fields., Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode cdf4a16 48/98: rec-mode: rec-cmd-count now suggests a default selection expression when invoked with a numeric prefix., Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode 033a600 64/98: rec-mode: new constant rec-mode-version, Stefan Monnier, 2020/11/12
- [elpa] externals/rec-mode 460a48d 65/98: copyright years updated in some files, Stefan Monnier, 2020/11/12