branch: externals/objed
commit e046331f947220c0af3ef1d4c55d6e17bf71d571
Author: Philip K <[email protected]>
Commit: GitHub <[email protected]>
Implemented objed-local-mode (#72)
* Implemented objed-local-mode
* Mention objed-mode in README
* Updated comments in objed-local-mode
---
README.asc | 17 ++++++++++++-----
objed.el | 14 ++++++++++++++
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/README.asc b/README.asc
index ae49342..716be79 100644
--- a/README.asc
+++ b/README.asc
@@ -21,11 +21,11 @@ file.
== Introduction
Text objects are textual patterns like a line, a top level definition, a word,
-a sentence or any other unit of text. When `objed-mode` is enabled, certain
-editing commands (configurable) will activate `objed` and enable its modal
-editing features. When active, keys which would usually insert a character are
-mapped to objed commands. Other keys and commands will continue to work as
-they normally would and exit this editing state again.
+a sentence or any other unit of text. When `objed-mode` or `objed-local-mode`
+is enabled, certain editing commands (configurable) will activate `objed` and
+enable its modal editing features. When active, keys which would usually insert
+a character are mapped to objed commands. Other keys and commands will continue
+to work as they normally would and exit this editing state again.
By default important editing keys like kbd:[Space], kbd:[DEL] or kbd:[Return]
are not bound to modal commands and will execute the regular command and exit
@@ -458,6 +458,7 @@ M-x package-install RET objed RET
;; activate objed-mode in you init
(objed-mode)
```
+
For manual installation:
```sh
@@ -475,6 +476,12 @@ Add this to your init file:
;; (global-set-key (kbd "M-SPC") 'objed-activate)
```
+In case you don't want to enable `objed` globally, use `objed-local-mode`:
+
+```emacs
+(add-hook 'prog-mode-hook #'objed-local-mode)
+```
+
== Contribute
I'm happy to receive pull requests or ideas to improve this package. Some
diff --git a/objed.el b/objed.el
index 17020f3..3bdfe58 100644
--- a/objed.el
+++ b/objed.el
@@ -4134,6 +4134,20 @@ To define your own text objects and editing operations
see
;; auto entry cmds
(advice-remove f #'objed--init-later))))
+(define-minor-mode objed-local-mode
+ "Enable `objed-mode' in current buffer."
+ :variable (buffer-local-value 'objed-mode (current-buffer))
+ ;; Same mechanism as in electric-{indent,layout,quote}-mode
+ (cond
+ ((eq objed-mode (default-value 'objed-mode))
+ ;; If the local value is set to the default value, unmark
+ ;; `objed-mode' as local
+ (kill-local-variable 'objed-mode))
+ ((not (default-value 'objed-mode))
+ ;; If `objed-mode' isn't enabled by default, enable it globally to
+ ;; invoke the setup routines, and then reset the default value
+ (objed-mode 1)
+ (setq-default objed-mode nil))))
(defun objed--install-advices-for (cmds obj)
"Given a list of commands CMDS install advices for OBJ.