[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/objed a94bfdf 145/216: Add extend functionality
From: |
Stefan Monnier |
Subject: |
[elpa] externals/objed a94bfdf 145/216: Add extend functionality |
Date: |
Tue, 8 Jan 2019 12:29:28 -0500 (EST) |
branch: externals/objed
commit a94bfdfb3b32527b0b30be9e077075490ad8bdd2
Author: Clemera <address@hidden>
Commit: Clemera <address@hidden>
Add extend functionality
---
objed-objects.el | 35 +++++++++++++++++++++++++++--------
objed.el | 52 ++++++++++++++++++++++++++++++++++++----------------
2 files changed, 63 insertions(+), 24 deletions(-)
diff --git a/objed-objects.el b/objed-objects.el
index 77001c8..21477fe 100644
--- a/objed-objects.el
+++ b/objed-objects.el
@@ -397,6 +397,8 @@ OBJ is the object to use and defaults to
`objed--current-obj'."
(let ((obj (or obj objed--current-obj)))
(objed--apply #'max obj)))
+(defvar objed--extend-ov nil
+ "Overlay of extended object.")
(defun objed--current (&optional obj)
"Get the current range of interest.
@@ -405,9 +407,24 @@ If the region is active the range is defined by the region
bounds
otherwise the its the head of object OBJ which defaults to
`objed--current-obj'."
(let ((obj (or obj objed--current-obj)))
- (if (region-active-p)
- (list (region-beginning) (region-end))
- (car obj))))
+ (cond (objed--extend-ov
+ (cond ((<= (point)
+ (overlay-start objed--extend-ov))
+ (list (objed--beg)
+ (overlay-end objed--extend-ov)))
+ ((>= (point)
+ (overlay-end objed--extend-ov))
+ (list (overlay-start objed--extend-ov)
+ (if (eq objed--object 'char)
+ (point)
+ (objed--end))))
+ (t
+ (list (overlay-start objed--extend-ov)
+ (overlay-end objed--extend-ov)))))
+ ((region-active-p)
+ (list (region-beginning) (region-end)))
+ (t
+ (car obj)))))
(defun objed--bounds (&optional obj)
"Get the current object bounds.
@@ -1016,7 +1033,6 @@ object."
(objed--goto-char (objed--beg obj)))))))
-
(defun objed--make-object-overlay (&optional obj)
"Create an overlay to mark current object.
@@ -1026,12 +1042,15 @@ OBJ is the object to use and defaults to
`objed--current-obj'."
(objed--end obj))))
-(defun objed--make-mark-overlay (beg end)
- "Make an objed overaly over region between BEG, END."
+(defun objed--make-mark-overlay (beg end &optional face keep)
+ "Make an objed overaly over region between BEG, END.
+
+Uses FACE `objed-mark' by default. If KEEP is non-nil keep
+overlays without content."
(let ((ov (make-overlay beg end)))
(overlay-put ov 'objed t)
- (overlay-put ov 'face 'objed-mark)
- (overlay-put ov 'evaporate t)
+ (overlay-put ov 'face (or face 'objed-mark))
+ (overlay-put ov 'evaporate (not keep))
(overlay-put ov 'rear-nonsticky t)
ov))
diff --git a/objed.el b/objed.el
index 25f24d6..c551e55 100644
--- a/objed.el
+++ b/objed.el
@@ -137,7 +137,6 @@
;; * Faces
-
(defface objed-mark
'((t (:inherit region)))
"Face used for marked objects."
@@ -148,6 +147,11 @@
"Face used for highlighting textual content of current object."
:group 'objed-faces)
+(defface objed-extend
+ '((t (:inherit objed-hl)))
+ "Face used for extending objects."
+ :group 'objed-faces)
+
(defface objed-mode-line
'((t (:inherit mode-line-inactive)))
"Face used for the mode line hint."
@@ -566,6 +570,11 @@ cons of guessed object and its state."
;; TODO: support repeated invokation
(define-key map (kbd "C-u") 'universal-argument)
(define-key map (kbd "C-SPC") 'set-mark-command)
+ ;; TODO: birdview mode/scroll mode
+ (define-key map (kbd "C-v") 'scroll-up-command)
+ (define-key map "\ev" 'scroll-down-command)
+ ;; "visual"
+ (define-key map "v" 'objed-extend)
;;(define-key map (kbd "C-h") which-key-C-h-map)
(define-key map (kbd "C-h k") 'describe-key)
@@ -625,11 +634,6 @@ cons of guessed object and its state."
(define-key map "i" 'objed-toggle-state)
(define-key map "q" 'objed-toggle-side)
- ;; TODO: birdview mode/scroll mode
- (define-key map "v" 'scroll-up-command)
- (define-key map "\ev" 'scroll-down-command)
- (define-key map "V" 'scroll-down-command)
-
;; marking/unmarking
(define-key map "m" 'objed-mark)
;; mark upwards
@@ -1158,10 +1162,9 @@ Reinitializes current object and removes itself from the
hook."
(defun objed-hl-function ()
"Function used as default for `hl-line-range-function'."
- (when (and objed--buffer objed--current-obj
- ;; the region is the current text object now
- (not (region-active-p)))
- (cons (objed--beg) (objed--end))))
+ (when (and objed--buffer objed--current-obj)
+ (let ((curr (objed--current)))
+ (cons (car curr) (cadr curr)))))
;; * Help commands
@@ -1670,12 +1673,24 @@ Default to sexp at point."
(t
(objed--end))))))
+(defvar objed--extend-cookie nil
+ "Cookie for extend region.")
-(defun objed-select-object ()
- "Select current object with active region."
+(defun objed-extend ()
+ "Extend current object."
(interactive)
- (push-mark (objed--end) t t)
- (goto-char (objed--beg)))
+ (when objed--extend-ov
+ (delete-overlay objed--extend-ov))
+ ;; the region should look like extend object.
+ (setq objed--extend-cookie
+ (face-remap-add-relative 'region 'objed-extend))
+ (setq objed--extend-ov
+ (objed--make-mark-overlay
+ (objed--beg) (if (eq objed--object 'char)
+ (objed--beg)
+ (objed--end))
+ 'objed-extend t))
+ (push-mark (point) t t))
(defun objed-contents-object ()
"Switch to reference of an object.
@@ -1931,7 +1946,8 @@ Each state is a list of the form:
"Return current state data."
(list (current-buffer)
(point) objed--object
- (objed--copy-object) objed--obj-state
+ (objed--copy-object)
+ objed--obj-state
(and objed--marked-ovs
(let ((os nil))
(dolist (ov objed--marked-ovs (nreverse os))
@@ -1950,7 +1966,6 @@ To be used in `pre-command-hook'."
objed--last-states)))))
-
(defun objed--restore-state (&optional state)
"Restore state STATE.
@@ -2675,6 +2690,11 @@ on."
(delete-overlay ov))
(setq objed--marked-ovs nil))
+ (when objed--extend-ov
+ (delete-overlay objed--extend-ov)
+ (setq objed--extend-ov nil)
+ (face-remap-remove-relative objed--extend-cookie))
+
(while objed--saved-vars
(let ((setting (pop objed--saved-vars)))
(if (consp setting)
- [elpa] externals/objed 92fd6e7 135/216: Fix marking instances in objects not surrounding point, (continued)
- [elpa] externals/objed 92fd6e7 135/216: Fix marking instances in objects not surrounding point, Stefan Monnier, 2019/01/08
- [elpa] externals/objed b9866d6 101/216: Fix undo op behavior, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 0e1d041 105/216: Simplify object macro usage, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 69db302 126/216: Some mroe init changes, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 0c5a4e3 147/216: Version bump, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 7617799 136/216: Allow testing different emacs versions, Stefan Monnier, 2019/01/08
- [elpa] externals/objed f5904c2 142/216: Add eval commands to keeper commands, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 734711a 124/216: Add move-to-window-line-top-bottom to activation cmds, Stefan Monnier, 2019/01/08
- [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 <=
- [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, 2019/01/08
- [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