[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/objed faa9fb0 158/166: Allow defining objects without e
From: |
Clemens Radermacher |
Subject: |
[elpa] externals/objed faa9fb0 158/166: Allow defining objects without ending regexp (#58) |
Date: |
Sun, 29 Dec 2019 08:21:19 -0500 (EST) |
branch: externals/objed
commit faa9fb049287255f9f25bdcfc95452d61fd3763e
Author: Clemens Radermacher <address@hidden>
Commit: Clemens Radermacher <address@hidden>
Allow defining objects without ending regexp (#58)
---
objed-objects.el | 110 ++++++++++++++++++++++++++++++++++---------------------
1 file changed, 69 insertions(+), 41 deletions(-)
diff --git a/objed-objects.el b/objed-objects.el
index 415c801..06702dd 100644
--- a/objed-objects.el
+++ b/objed-objects.el
@@ -70,7 +70,7 @@
(eval-and-compile
(require 'rx)
(defun objed--get-regex-object (bregex eregex)
- "Return regex object between BREGEX and EREGEX.
+ "Return regex object between BREGEX and EREGEX.
The inner object part will be the text between the matches for
those two expressions.
@@ -81,45 +81,68 @@ of this group will belong to the inner object part.
EREGEX is the regular expression for the end of the object. If
the regular expressions contains a group, any text which is part
-of this group will belong to the inner object part."
- (let* ((obounds ())
- (ibounds ())
- (opos (point)))
- (save-mark-and-excursion
- ;; try to move into object when at boundary
- (if (looking-at bregex)
- (goto-char (or (match-end 1)
- (match-end 0)))
- (if (looking-back eregex (line-beginning-position))
+of this group will belong to the inner object part.
+
+EREGEX can also be an empty string. In this case objects are
+separated by the BREGEX expression and reach until the next one
+or until the buffer end if no next instance can be found."
+ (let* ((obounds ())
+ (ibounds ())
+ (opos (point)))
+ (save-mark-and-excursion
+ ;; try to move into object when at boundary
+ (if (looking-at bregex)
+ (goto-char (or (match-end 1)
+ (match-end 0)))
+ (if (looking-back eregex (line-beginning-position))
+ (goto-char (or (match-beginning 1)
+ (match-beginning 0)))
+ (re-search-forward eregex nil t)
(goto-char (or (match-beginning 1)
- (match-beginning 0)))
- (re-search-forward eregex nil t)
- (goto-char (or (match-beginning 1)
- (match-beginning 0)))))
- (when (and ;; goto possible start
- (re-search-backward bregex nil t)
- (push (or (match-beginning 1)
- (match-end 0))
- ibounds)
- (push (match-beginning 0)
- obounds)
- ;; goto possible end
- (goto-char (or (match-end 1)
- (match-end 0)))
- (re-search-forward eregex nil t)
- (push (or (match-end 1)
- (match-beginning 0))
- ibounds)
- (push (match-end 0)
- obounds)
- ;; when point was within start and end
- (<= (cadr obounds) opos (car obounds)))
- (list (nreverse obounds)
- (nreverse ibounds))))))
+ (match-beginning 0)))))
+ (when (and ;; goto possible start
+ (re-search-backward bregex nil t)
+ (push (or (match-beginning 1)
+ (match-end 0))
+ ibounds)
+ (push (match-beginning 0)
+ obounds)
+ ;; goto possible end
+ (goto-char (or (match-end 1)
+ (match-end 0)))
+ (cond ((string= "" eregex)
+ ;; no end provided, objects are separated by beginning
+ ;; regex
+ (cond ((re-search-forward bregex nil t)
+ (push (match-beginning 0) obounds)
+ ;; no way to tell so just skip ws
+ ;; to have a sensible default
+ (goto-char (car obounds))
+ (objed--skip-ws t)
+ (push (point) ibounds))
+ (t
+ ;; if there is no match that means the buffer is
+ ;; the object end
+ (goto-char (point-max))
+ (push (point) obounds)
+ (objed--skip-ws t)
+ (push (point) ibounds))))
+ (t
+ (re-search-forward eregex nil t)
+ (push (or (match-end 1)
+ (match-beginning 0))
+ ibounds)
+ (push (match-end 0)
+ obounds)))
+ ;; when point was within start and end
+ (<= (cadr obounds) opos (car obounds)))
+ (list (nreverse obounds)
+ (nreverse ibounds))))))
(defun objed--transform-pos-data (plist)
(cond ((and (plist-get plist :beg)
- (plist-get plist :end))
+ (or (plist-get plist :end)
+ (stringp (plist-get plist :beg))))
(let ((np nil)
(alt nil)
(skip nil))
@@ -139,16 +162,21 @@ of this group will belong to the inner object part."
;; merge ... :get-obj "regex search"
(if (and (stringp (plist-get plist :beg))
- (stringp (plist-get plist :end)))
+ (or (stringp (plist-get plist :end))
+ (not (plist-get plist :end))))
(let ((bregex (plist-get plist :beg))
- (eregex (plist-get plist :end)))
+ (eregex (or (plist-get plist :end)
+ "")))
(append np
(list :try-prev)
- (list `(when (re-search-backward ,eregex)
- (goto-char (match-beginning 0))))
+ (if (string= "" eregex)
+ (list `(when (re-search-backward ,bregex)
+ (goto-char (match-end 0))))
+ (list `(when (re-search-backward ,eregex)
+ (goto-char (match-beginning 0)))))
(list :try-next)
(list `(when (re-search-forward ,bregex)
- (goto-char (match-end 0))))
+ (goto-char (match-end 0))))
(list :get-obj)
(list
`(objed--get-regex-object ,bregex
- [elpa] externals/objed 69dcc5b 066/166: Use first regex group of regex object to delemit inner part, (continued)
- [elpa] externals/objed 69dcc5b 066/166: Use first regex group of regex object to delemit inner part, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed 210d3db 077/166: Improve sexp object for non symetric commands, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed fa06574 075/166: Don't init when other modes have set overriding-terminal-local-map, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed 752d11e 080/166: Change binding for sexp object, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed 50f79c8 091/166: Include textblock for block expansion when at comment, too, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed dcea2bc 124/166: Add window resize commands, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed fc93d49 134/166: Improve error object when flymake is used, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed d111035 140/166: Require mc if necessary, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed 6a2663e 138/166: Don't bind C-o by default, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed dc23da4 153/166: Add objed-exit-hook #57, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed faa9fb0 158/166: Allow defining objects without ending regexp (#58),
Clemens Radermacher <=
- [elpa] externals/objed 2a25ff2 081/166: Make toggle smarter for sexp objects, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed 2f50485 102/166: Add css defun object, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed d3ab36c 108/166: Add kill-this-buffer to command alist, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed be4c3cd 114/166: Make indenting defuns repeatable, too, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed 4a22002 120/166: Improve reformat command, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed 9267f38 125/166: Improve open line command, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed cab7cee 130/166: Update hl init, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed 7374a35 128/166: Improve sexp fallback, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed 42a553e 139/166: Don't override M-o binding, Clemens Radermacher, 2019/12/29
- [elpa] externals/objed 4d1a445 141/166: Add public object bounds functions, Clemens Radermacher, 2019/12/29