[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/el-search 33c14a4 103/332: Move some pattern definition
From: |
Stefan Monnier |
Subject: |
[elpa] externals/el-search 33c14a4 103/332: Move some pattern definitions to new file "el-search-x" |
Date: |
Tue, 1 Dec 2020 15:48:21 -0500 (EST) |
branch: externals/el-search
commit 33c14a456a89a15dfda0e364cea5b3c0732d9c22
Author: Michael Heerdegen <michael_heerdegen@web.de>
Commit: Michael Heerdegen <michael_heerdegen@web.de>
Move some pattern definitions to new file "el-search-x"
---
el-search-x.el | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
el-search.el | 72 ++----------------------------------
2 files changed, 116 insertions(+), 69 deletions(-)
diff --git a/el-search-x.el b/el-search-x.el
new file mode 100644
index 0000000..8b8c10b
--- /dev/null
+++ b/el-search-x.el
@@ -0,0 +1,113 @@
+;;; el-search-x.el --- Additional pattern definitions for el-search -*-
lexical-binding: t -*-
+
+;; Copyright (C) 2016 Free Software Foundation, Inc
+
+;; Author: Michael Heerdegen <michael_heerdegen@web.de>
+;; Maintainer: Michael Heerdegen <michael_heerdegen@web.de>
+;; Created: 2016_08_03
+;; Keywords: lisp
+
+
+;; This file is not part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+
+;;; Commentary:
+
+;; This file contains additional definitions of el-search patterns.
+;; You can just `require' this file, but doing so is not mandatory for
+;; using el-search.
+
+
+;;; Code:
+
+(require 'el-search)
+
+
+;;;; `change', `changed'
+
+(defvar diff-hl-reference-revision)
+(declare-function diff-hl-changes "diff-hl")
+(defvar-local el-search--cached-changes nil)
+
+(defun el-search--changes-from-diff-hl (revision)
+ "Return a list of changed regions (as conses of positions) since REVISION.
+Use variable `el-search--cached-changes' for caching."
+ (if (and (consp el-search--cached-changes)
+ (equal (car el-search--cached-changes)
+ revision))
+ (cdr el-search--cached-changes)
+ (require 'diff-hl)
+ ;; `diff-hl-changes' returns line numbers. We must convert them into
positions.
+ (save-restriction
+ (widen)
+ (save-excursion
+ (let ((diff-hl-reference-revision revision)
+ (current-line-nbr 1) change-beg)
+ (goto-char 1)
+ (cdr (setq el-search--cached-changes
+ (cons revision
+ (delq nil (mapcar (pcase-lambda (`(,start-line
,nbr-lines ,kind))
+ (if (eq kind 'delete) nil
+ (forward-line (- start-line
current-line-nbr))
+ (setq change-beg (point))
+ (forward-line (1- nbr-lines))
+ (setq current-line-nbr (+
start-line nbr-lines -1))
+ (cons change-beg
(line-end-position))))
+ (diff-hl-changes)))))))))))
+
+(defun el-search--change-p (posn &optional revision)
+ ;; Non-nil when sexp after POSN is part of a change
+ (when (buffer-modified-p)
+ (error "Buffer is modified - please save"))
+ (save-restriction
+ (widen)
+ (let ((changes (el-search--changes-from-diff-hl revision))
+ (sexp-end (scan-sexps posn 1)))
+ (while (and changes (< (cdar changes) sexp-end))
+ (pop changes))
+ (and changes
+ (<= (caar changes) posn)))))
+
+(defun el-search--changed-p (posn &optional revision)
+ ;; Non-nil when sexp after POSN contains a change
+ (when (buffer-modified-p)
+ (error "Buffer is modified - please save"))
+ (save-restriction
+ (widen)
+ (let ((changes (el-search--changes-from-diff-hl revision)))
+ (while (and changes (<= (cdar changes) posn))
+ (pop changes))
+ (and changes
+ (< (caar changes) (scan-sexps posn 1))))))
+
+(el-search-defpattern change (&optional revision)
+ "Matches the object if its text is part of a file change.
+
+Requires library \"diff-hl\". REVISION defaults to the file's
+repository's HEAD commit."
+ `(guard (el-search--change-p (point) ,revision)))
+
+(el-search-defpattern changed (&optional revision)
+ "Matches the object if its text contains a file change.
+
+Requires library \"diff-hl\". REVISION defaults to the file's
+repository's HEAD commit."
+ `(guard (el-search--changed-p (point) ,revision)))
+
+
+(provide 'el-search-x)
+
+;;; el-search-x.el ends here
diff --git a/el-search.el b/el-search.el
index 90ee996..fc68ae2 100644
--- a/el-search.el
+++ b/el-search.el
@@ -114,6 +114,9 @@
;; effect is limited to this package. See C-h f `el-search-pattern'
;; for a list of predefined additional pattern forms.
;;
+;; Some additional pattern definitions can be found in the file
+;; "el-search-x.el".
+;;
;;
;; Replacing
;; =========
@@ -918,75 +921,6 @@ the search pattern."
(point) ',property nil ,limit)
,limit))))))
-(defvar diff-hl-reference-revision)
-(declare-function diff-hl-changes "diff-hl")
-(defvar-local el-search--cached-changes nil)
-
-(defun el-search--changes-from-diff-hl (revision)
- "Return a list of changed regions (as conses of positions) since REVISION.
-Use variable `el-search--cached-changes' for caching."
- (if (and (consp el-search--cached-changes)
- (equal (car el-search--cached-changes)
- revision))
- (cdr el-search--cached-changes)
- (require 'diff-hl)
- ;; `diff-hl-changes' returns line numbers. We must convert them into
positions.
- (save-restriction
- (widen)
- (save-excursion
- (let ((diff-hl-reference-revision revision)
- (current-line-nbr 1) change-beg)
- (goto-char 1)
- (cdr (setq el-search--cached-changes
- (cons revision
- (delq nil (mapcar (pcase-lambda (`(,start-line
,nbr-lines ,kind))
- (if (eq kind 'delete) nil
- (forward-line (- start-line
current-line-nbr))
- (setq change-beg (point))
- (forward-line (1- nbr-lines))
- (setq current-line-nbr (+
start-line nbr-lines -1))
- (cons change-beg
(line-end-position))))
- (diff-hl-changes)))))))))))
-
-(defun el-search--change-p (posn &optional revision)
- ;; Non-nil when sexp after POSN is part of a change
- (when (buffer-modified-p)
- (error "Buffer is modified - please save"))
- (save-restriction
- (widen)
- (let ((changes (el-search--changes-from-diff-hl revision))
- (sexp-end (scan-sexps posn 1)))
- (while (and changes (< (cdar changes) sexp-end))
- (pop changes))
- (and changes
- (<= (caar changes) posn)))))
-
-(defun el-search--changed-p (posn &optional revision)
- ;; Non-nil when sexp after POSN contains a change
- (when (buffer-modified-p)
- (error "Buffer is modified - please save"))
- (save-restriction
- (widen)
- (let ((changes (el-search--changes-from-diff-hl revision)))
- (while (and changes (<= (cdar changes) posn))
- (pop changes))
- (and changes
- (< (caar changes) (scan-sexps posn 1))))))
-
-(el-search-defpattern change (&optional revision)
- "Matches the object if its text is part of a file change.
-
-Requires library \"diff-hl\". REVISION defaults to the file's
-repository's HEAD commit."
- `(guard (el-search--change-p (point) ,revision)))
-
-(el-search-defpattern changed (&optional revision)
- "Matches the object if its text contains a file change.
-
-Requires library \"diff-hl\". REVISION defaults to the file's
-repository's HEAD commit."
- `(guard (el-search--changed-p (point) ,revision)))
-
;;;; Highlighting
- [elpa] externals/el-search e5bd647 214/332: * el-search/el-search.el: Work around Emacs Bug#29857, (continued)
- [elpa] externals/el-search e5bd647 214/332: * el-search/el-search.el: Work around Emacs Bug#29857, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search d995af1 166/332: Don't let el-search-pattern resume a paused search, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search ceb23fc 169/332: More multi query-replace related improvements, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 1aded2b 172/332: Make amount of context around occur matches adjustable, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search dc1d703 175/332: Require the new rmc.el lib when available, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 419a9c2 176/332: Improve jumping to matches in *El Occur* buffers, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 8c3213f 182/332: Bump el-search version to 1.4, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search d3eaaf0 198/332: Make the some-context function include an opening backquote, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 85fdccc 202/332: New option value ask-multi for `el-search-auto-save-buffers', Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 92efda8 101/332: Add comment about (pcase) backquote inside (real) backquote, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 33c14a4 103/332: Move some pattern definitions to new file "el-search-x",
Stefan Monnier <=
- [elpa] externals/el-search c4d8e00 105/332: el-search--make-docstring: exclude some specially named patterns, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 0735984 120/332: el-search: more cleanup and minor tweaks; version 1.0.1, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 6292dcc 130/332: Fix disregarding compressed elisp files, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 788db9d 135/332: Use regexp-opt on suffixes in el-search--elisp-file-name-p, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search e7e900c 145/332: Use `read' to circumvent bug#24542, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 8e6466a 131/332: Set syntax table for temp buffers in el-search-atom-list, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search cdfe8c1 136/332: Call `user-error' instead of `error' where appropriate, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 5fbbcd1 168/332: Restore current search head in case of error or quit, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search 6e4b9cc 170/332: Show line numbers in *El Occur* buffers, Stefan Monnier, 2020/12/01
- [elpa] externals/el-search a20a333 171/332: Use a separate function to document defined pattern types, Stefan Monnier, 2020/12/01