[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/objed fbabb7a 178/216: Add command to insert new object
From: |
Stefan Monnier |
Subject: |
[elpa] externals/objed fbabb7a 178/216: Add command to insert new object of current type |
Date: |
Tue, 8 Jan 2019 12:29:35 -0500 (EST) |
branch: externals/objed
commit fbabb7aa8010308180ab8b2c55164333275ec845
Author: Clemera <address@hidden>
Commit: Clemera <address@hidden>
Add command to insert new object of current type
---
objed-objects.el | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++---
objed.el | 51 ++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 97 insertions(+), 8 deletions(-)
diff --git a/objed-objects.el b/objed-objects.el
index def9a75..84d9b48 100644
--- a/objed-objects.el
+++ b/objed-objects.el
@@ -361,7 +361,8 @@ Either the symbol `whole' or `inner'.")
(defun objed--beg (&optional obj)
"Get beginning position of object.
-OBJ is the object to use and defaults to `objed--current-obj'."
+Ignores current object state. OBJ is the object to use and
+defaults to `objed--current-obj'."
(let ((obj (or obj objed--current-obj)))
(caar obj)))
@@ -369,14 +370,16 @@ OBJ is the object to use and defaults to
`objed--current-obj'."
(defun objed--end (&optional obj)
"Get end position of object.
-OBJ is the object to use and defaults to `objed--current-obj'."
+Ignores current object state. OBJ is the object to use and
+defaults to `objed--current-obj'."
(let ((obj (or obj objed--current-obj)))
(cadr (car obj))))
(defun objed--other (&optional obj)
"Return object position opposite to point.
-OBJ is the object to use and defaults to `objed--current-obj'."
+Ignores current object state. OBJ is the object to use and
+defaults to `objed--current-obj'."
(let ((obj (or obj objed--current-obj)))
(if (/= (point) (objed--end))
(objed--end obj)
@@ -445,6 +448,51 @@ OBJ is the object to use and defaults to
`objed--current-obj'."
(posn (objed--alt obj)))
(cadr posn)))
+(defun objed--obeg (&optional obj)
+ "Get beginning position of object.
+
+OBJ is the object to use and defaults to `objed--current-obj'."
+ (let ((obj (or obj objed--current-obj)))
+ (if (objed--inner-p)
+ (objed--alt-beg obj)
+ (objed--beg obj))))
+
+(defun objed--oend (&optional obj)
+ "Get end position of object.
+
+OBJ is the object to use and defaults to `objed--current-obj'"
+ (let ((obj (or obj objed--current-obj)))
+ (if (objed--inner-p)
+ (objed--alt-end obj)
+ (objed--end obj))))
+
+(defun objed--ibeg (&optional obj)
+ "Get inner beginning position of object.
+
+OBJ is the object to use and defaults to `objed--current-obj'."
+ (let ((obj (or obj objed--current-obj)))
+ (if (objed--inner-p)
+ (objed--beg obj)
+ (objed--alt-beg obj))))
+
+(defun objed--iend (&optional obj)
+ "Get inner end position of object.
+
+OBJ is the object to use and defaults to `objed--current-obj'."
+ (let ((obj (or obj objed--current-obj)))
+ (if (objed--inner-p)
+ (objed--end obj)
+ (objed--alt-end obj))))
+
+(defun objed--get-left-boundary ()
+ "Get left boundary of current object."
+ (buffer-substring (objed--obeg) (objed--ibeg)))
+
+(defun objed--get-right-boundary ()
+ "Get right boundary of current object."
+ (buffer-substring (objed--iend) (objed--oend)))
+
+
(defun objed--goto-char (pos)
"Move to position POS possibly skipping leading whitespace."
(goto-char
diff --git a/objed.el b/objed.el
index 07171f4..b618a02 100644
--- a/objed.el
+++ b/objed.el
@@ -712,6 +712,8 @@ BEFORE and AFTER are forms to execute before/after calling
the command."
(define-key map "|"
(objed-define-op nil objed-ipipe))
+ ;; (define-key map (kbd "<C-return>") 'objed-quickrun)
+ (define-key map (kbd "<M-return>") 'objed-insert-new-object)
(define-key map "!"
(objed-define-op nil objed-replace-op))
@@ -2653,14 +2655,12 @@ Returns cons cell with cmd as car and possible
arguemtns as cdr."
(buffer-substring (point) (line-end-position))))))
-(defun objed--ipipe-to-string (cmd-args str)
+(defun objed--ipipe-to-string (cmdline str)
"Pipe string STR through CMD-ARGS.
Return restult if any or nil."
- (let* ((cmdline (minibuffer-contents))
- (parsed (objed--ipipe-parse cmdline))
- (cmd (car-safe parsed))
- (args (cdr-safe parsed)))
+ (let* ((parsed (objed--ipipe-parse cmdline))
+ (cmd (car-safe parsed)))
(cond ((and cmd (executable-find cmd))
(with-temp-buffer
(let ((exit (call-process-region
@@ -2760,6 +2760,47 @@ Commands can be shell commands or region commands."
(remove-hook 'after-change-functions 'objed--ipipe-schedule-time t)))
(delete-overlay objed--ipipe-overlay)))
+(defun objed-insert-new-object ()
+ "Insert boundaries of object after current one."
+ (interactive)
+ (let* ((opos (objed--oend))
+ (left (objed--get-left-boundary))
+ (right (objed--get-right-boundary))
+ (oc (buffer-substring (objed--obeg) (objed--oend)))
+ (ic (buffer-substring (objed--ibeg) (objed--iend)))
+ (linep (objed--line-p oc))
+ (lispy (derived-mode-p 'lisp-mode
+ 'emacs-lisp-mode
+ 'clojure-mode
+ 'racket-mode
+ 'lisp-interaction-mode))
+ (nb nil))
+ (goto-char opos)
+ (if (string= ic oc)
+ (insert " " oc)
+ (insert (format "%s%s"
+ (if (and linep
+ (not (string= "" ic))
+ (not (string-match "\\`\n\\|\n\\'" right))
+ (not (string-match "\\`\n\\|\n\\'" left)))
+ "\n"
+ (if (string-match "\n\\'" oc) ""
+ (if (looking-at "\n") "\n" " ")))
+ left))
+ ;; stay in the middle
+ (save-excursion
+ (insert (format "%s" right))))
+ ;; dumb search for probably best pos
+ (when (re-search-backward "\\_>" opos t)
+ (re-search-backward "\\_<" opos t))
+ (if (and (not lispy)
+ (setq nb (bounds-of-thing-at-point 'list)))
+ (goto-char (car nb))
+ (when lispy
+ (indent-according-to-mode)))
+ ;; goto ref if there is one...
+ (objed--exit-objed)))
+
;; * Exit active state
(defun objed--line-p (text)
- [elpa] externals/objed 9c816e2 133/216: Improve mark all for repeated object invokation, (continued)
- [elpa] externals/objed 9c816e2 133/216: Improve mark all for repeated object invokation, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 8e9ab88 152/216: Markup, Stefan Monnier, 2019/01/08
- [elpa] externals/objed a94bfdf 145/216: Add extend functionality, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 0de9c61 159/216: Further improve objed-expand, Stefan Monnier, 2019/01/08
- [elpa] externals/objed ac6ecb0 149/216: Mention new extend functionality, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 4a84e59 174/216: Bind this-command when executing region command, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 60c4731 139/216: Remove key binding info in header, use readme for that, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 62c2dee 118/216: Improve move object code, Stefan Monnier, 2019/01/08
- [elpa] externals/objed c88bb7b 134/216: Mention new functionality, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 6951f1b 177/216: Add convenience bindings for forward/backward until buffer, Stefan Monnier, 2019/01/08
- [elpa] externals/objed fbabb7a 178/216: Add command to insert new object of current type,
Stefan Monnier <=
- [elpa] externals/objed d792eb0 160/216: Dont reinit object for first extend, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 7f575aa 180/216: Fix dispatch, when no object found, Stefan Monnier, 2019/01/08
- [elpa] externals/objed f643281 171/216: Correct key names, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 639dc87 163/216: Add interactive pipe op, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 179ac60 185/216: Update docs for exit-op, Stefan Monnier, 2019/01/08
- [elpa] externals/objed de09955 153/216: Markup fixes again, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 4489ea3 187/216: Fixup forward word extend when already at word end pos, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 9a0ea65 192/216: Fix override of default for comint-prompt-regexp, Stefan Monnier, 2019/01/08
- [elpa] externals/objed a7b9df6 183/216: Add C-RET, M-RET for eval-in-repl and inserting new object, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 5ca0678 195/216: Indent for tab command should not activate objed, Stefan Monnier, 2019/01/08