All Projects → clemera → Objed

clemera / Objed

Licence: gpl-3.0
Navigate and edit text objects with Emacs. Development on pause.

Labels

Projects that are alternatives of or similar to Objed

Company Lsp
Company completion backend for lsp-mode
Stars: ✭ 238 (-13.77%)
Mutual labels:  emacs
Emacs.d
My Emacs configuration, literately 😄
Stars: ✭ 254 (-7.97%)
Mutual labels:  emacs
Emacs Theme Darktooth
Darktooth : From the darkness... it watches.
Stars: ✭ 270 (-2.17%)
Mutual labels:  emacs
Evil Org Mode
Supplemental evil-mode keybindings to emacs org-mode
Stars: ✭ 241 (-12.68%)
Mutual labels:  emacs
Zoom
Fixed and automatic balanced window layout for Emacs
Stars: ✭ 252 (-8.7%)
Mutual labels:  emacs
Mu4e Dashboard
A dashboard for mu4e (mu for emacs)
Stars: ✭ 259 (-6.16%)
Mutual labels:  emacs
Emacs Easy Hugo
Emacs major mode for managing hugo
Stars: ✭ 235 (-14.86%)
Mutual labels:  emacs
Ivy Rich
More friendly interface for ivy.
Stars: ✭ 274 (-0.72%)
Mutual labels:  emacs
Dracula Theme
🧛🏻‍♂️ One theme. All platforms.
Stars: ✭ 17,480 (+6233.33%)
Mutual labels:  emacs
Unpackaged.el
A collection of useful Emacs Lisp code that isn't substantial enough to be packaged
Stars: ✭ 269 (-2.54%)
Mutual labels:  emacs
Academic Phrases
Bypass that mental block when writing your papers.
Stars: ✭ 244 (-11.59%)
Mutual labels:  emacs
Yay Evil Emacs
😈 A lightweight literate Emacs config with even better "better defaults". Shipped with a custom theme!
Stars: ✭ 250 (-9.42%)
Mutual labels:  emacs
Org Projectile
Manage org-mode TODOs for your projectile projects
Stars: ✭ 259 (-6.16%)
Mutual labels:  emacs
Git Link
Emacs package to get the GitHub/Bitbucket/GitLab/... URL for a buffer location
Stars: ✭ 239 (-13.41%)
Mutual labels:  emacs
Emacs.d
My emacs configuration documented in literate programming style
Stars: ✭ 271 (-1.81%)
Mutual labels:  emacs
Ido Completing Read Plus
Fancy completion all over Emacs, not just for buffers and files.
Stars: ✭ 237 (-14.13%)
Mutual labels:  emacs
Counsel Projectile
Ivy UI for Projectile
Stars: ✭ 255 (-7.61%)
Mutual labels:  emacs
Cloudmacs
Selfhost your Emacs and access it in browser
Stars: ✭ 277 (+0.36%)
Mutual labels:  emacs
Org Superstar Mode
Make org-mode stars a little more super
Stars: ✭ 271 (-1.81%)
Mutual labels:  emacs
Org Transclusion
(alpha) Emacs package to enable transclusion with Org Mode
Stars: ✭ 251 (-9.06%)
Mutual labels:  emacs

:experimental:

++++ GNU ELPA MELPA Stable MELPA ++++

= Objed - The text object editor

Development is currently paused but I have plans for a complete overhaul of the project. Objed is completely usable in its current state but note that its public interface is subject to change.

A global minor-mode to navigate and edit text objects. Objed also enables modal editing and composition of commands. It combines ideas of http://emacs-versor.sourceforge.net/[versor-mode] and other Editors like Vim or Kakoune and tries to align them with regular Emacs conventions.

For more information you can read my https://with-emacs.com/posts/objed/[posts] about objed and for changes check the https://github.com/clemera/objed/blob/master/News.asc[News] 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 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 objed. Character movement exits objed, as well. This makes it convenient to move around and continue by adding/deleting text.

With activation objed shows the current object type in the mode-line. The textual content of the object is highlighted visually in the buffer and the cursor color is changed, too. The user can now navigate by units of this object, change the object state or switch to other object types.

The object state is either inner or whole and is indicated in the modeline by (i) or (w) after the object type. With inner state, anything that would be considered delimiters or padding around an object is excluded.

The user can apply operations to objects. By marking objects before applying an operation, s?he can even operate on multiple objects at once. This works similar to the way you interact with files in dired. When marking an object, the point moves on to the next object of this type.

The object type used for initialization is determined by the entry command (see objed-cmd-alist). For example, using beginning-of-defun will activate objed using the defun object as an initial object type. With the command next-line, objed would initialize with the line object. To activate objed without movement you can use objed-activate, bound to kbd:[M-SPC] by default. Objed uses the last command and its mapping in objed-command-alist to choose the initial object.

Objed's modal state provides basic movement commands which move by line, sexp word or character. Those commands automatically activate the corresponding object type. Other commands only activate the part between the initial position and the new position moved to. By repeating commands you can often expand/proceed to other objects. This way you can compose movement and editing operations very efficiently.

The expansion commands distinguish between block objects (objects built out of lines of text like paragraphs or text blocks with the same level of indentation and also comment blocks) and context objects (programming constructs like strings, brackets, comments or functions). This way you can quickly expand to the desired objects.

For example to move to the end of the paragraph, the user would first move to the end of the line with kbd:[Ctrl - e]. This would activate objed using the line object with the text moved over. The user can now continue to the end of the paragraph by pressing kbd:[e] again. Now s?he is able to proceed even further by pressing kbd:[e] again OR to continue by adding new text to the end of the paragraph OR to continue by acting on the text moved over, for example killing it by pressing kbd:[k].

As often with text editing, the explanation sounds more complicated than using it. To get a better impression of the editing workflow with objed I have added some animated demos below.

To learn more about available features and commands have a look at the descriptions below, the commentary section or the docstrings and bindings defined in objed-map. To define your own operations and text objects see objed-define-op and objed-define-object.

Examples of usage

Note that the key bindings shown in the screencasts below aren't up to date.

.Object navigation image::./images/object_nav.gif[Object navigation]

++++
++++

.Object expansion image::./images/expand_context.gif[Object expansion]

++++
++++

.End of block expansion image::./images/end_of_block.gif[End of block expansion]

++++
++++

.Upto context image::./images/upto.gif[Upto context]

++++
++++

.Marking objects and act on them image::./images/reorder_lines_by_marking.gif[Marking objects and act on them]

++++
++++

.Mark objects inside another one image::./images/remove_comments_in_defun.gif[Mark objects inside another one]

++++
++++

.Select current object type with avy image::./images/senteces_avy.gif[Select current object type with avy]

++++
++++

.Navigate and search output object image::./images/output_occur.gif[Navigate and search output object]

++++
++++

Keys

Although some features are still experimental the basic user interface will stay the same. The following gives an overview of available keys and commands. If commands allow for numeric arguments you can input them without the use of kbd:[Ctrl] or kbd:[Meta]. kbd:[0] can be used as an alternative for the universal argument (kbd:[C-u]). To add custom commands to the modal state you can use objed-user-map which is available under prefix key kbd:['] and objed-other-user-map bound to kbd:[-]. It's recommended to use one of these map for custom object bindings and the other one for additional operations.

You can customize the default bindings for object keys using objed-define-global-object-keys and also define major mode specific bindings using objed-define-local-object-keys.

In addition to the commands configured in objed-cmd-alist you can use the following commands to enter objed (those bindings are only active if you are using objed-mode, if you choose to activate objed always manually you have to bind those commands in your global-map):

[objed-mode-map] |=== |Shortcut |Purpose

|kbd:[M-SPC] |Activate objed, choosing initial object based on last-command and objed-cmd-alist.

|kbd:[M-#] |Choose an object and activate with it.

|kbd:[C-,/C-.] |Move to previous/next identifier and activate identifier object.

|kbd:[M-[] |Activate object at point (determined from context) and move to its start.

|kbd:[M-]] |Activate object at point (determined from context) and move to its end.

|kbd:[M-(] |Move to beginning of object at point and active text moved over.

|kbd:[M-)] |Move to end of object at point and active text moved over. |===

Basic movement commands (switch the object type on movement):

[objed-map] |=== |Shortcut |Purpose

|kbd:[l/h] |Move forward/backward one char and activate the char object

|kbd:[f/b] |Move forward/backward one sexp and activate the sexp object

|kbd:[s/r] |Move forward/backward one word and activate the word object.

|kbd:[n/p] |Move to the next/previous line and activate the line object. |===

Commands for block objects (objects built out of lines of text):

[objed-map] |=== |Shortcut |Purpose

|kbd:[v] |Activate (line based) object at point and move to its start. On repeat proceed to beginning of the indentation block, comment block, paragraph or other block objects.

|kbd:[a] |Move to beginning of line and activate the text moved over. On repeat proceed to beginning of blocks like explained above.

|kbd:[e] |Move to end of line and activate the text moved over. On repeat proceed to end of blocks like explained above. |===

Commands for context objects. Those objects are common programming constructs like defuns, strings, parentheses but also sentences inside comments for example. Any whitespace after point is skipped before determining the context:

[objed-map] |=== |Shortcut |Purpose

|kbd:[o] |Activate the inner part of the object at point and move to the start. This is useful to act on the content of the string, brackets and so on. On repeat expand to other objects around current position.

|kbd:[j] |Move point to the other side of the current object.

|kbd:[t] |Toggle object state. Switches between inner and whole object state.

|kbd:[[/]] |Move to the start of previous/next instance of current object type.

|kbd:[(/)] |Move to inner beginning/end of the object at point and activate the text moved over.

|kbd:[{/}] |Move forward/backward paragraph and switch to paragraph object

|kbd:[</>] |Goto first/last instance of current object type (https://with-emacs.com/posts/objed/spotlight-objed-move-to-first-or-last-instance/[blog]). |===

Commands to switch objects (and move point to its start, repeating an object command mark all instances in current defun/buffer):

[objed-map] |=== |Shortcut |Purpose |kbd:[.] |Switch to identifier object or move to next.

|kbd:[,] |Switch to identifier object and move to previous.

|kbd:[c] |Prefix to switch to other objects, see objed-object-map for available objects and objed-define-object to add your own (https://with-emacs.com/posts/objed/writing-your-own-text-objects-for-objed/[blog]). |===

Indent/Move objects around:

[objed-map] |=== |Shortcut |Purpose

|kbd:[C-left/C-right] |Move/indent all lines in object right/leftward.

|kbd:[M-left/M-right] |Move/indent all lines in object to right/leftward to tab stop.

|kbd:[C-M-left/C-M-right] |Slurp following sexp into current object/Barf last sexp out of current object.

|kbd:[S-left/S-right/S-up/S-down/F/B] |Move current object type forward/backward (https://with-emacs.com/posts/i-like-to-move-it-emacs-version/[blog]).

|kbd:[L/H] |Switch to char object and move it forward/backward.

|kbd:[S/R] |Switch to word object and move it forward/backward.

|kbd:[N/P] |Switch to line object and move it forward/backward. |===

Commands to edit objects (applying operations to them). When the region is active the operation acts on the current region. To act on multiple objects at once you can mark them first (see the "Misc commands" below):

[objed-map] |=== |Shortcut |Purpose

|kbd:[i] |Delete current object(s) and switch to insert.

|kbd:[k] |Kill current object(s). Continues by selecting the next instance from point.

|kbd:[K] |Kill current object. Continues by selecting the previous instance from point.

|kbd:[d] |Delete current object(s). Continues by selecting the next instance from point.

|kbd:[D] |Delete current object. Continues by selecting the previous instance from point.

|kbd:[w] |Copy current object(s). On repeat move to next and append it to kill-ring

|kbd:[y] |Yank last killed text at point. On repeat, cycle through kill-ring

|kbd:[\ ] |Indent object(s).

|kbd:[;] |Un/comment object(s).

|kbd:[%] |Query replace narrowed to current object.

|kbd:[^] |Replace object with inner part (raise).

|kbd:[!] |Run object contents as shell commands.

|kbd:[&] |Pipe object region through shell command.

|kbd:[|] |Incrementally construct command chain to replace text (https://with-emacs.com/posts/objed/incremental-construction-of-command-chains-to-replace-text/[blog]).

|kbd:[Ctrl - RET] |Evaluate current object in REPL (need eval-in-repl to be installed).

|kbd:[M - RET] |Duplicate object.

|kbd:[S - RET] |Comment and duplicate object.

|kbd:[C - M - RET] |Insert new (empty) instance of current object type. This inserts the object boundaries without the inner content.

|kbd:[$] |Spell check textual content of object using flyspell.

|kbd:[~] |Undo in current object region.

|kbd:["] |Add surroundings to object(s) with any pair using electric (built-in).

|kbd:[x] |Prefix to access other operations, see objed-op-map for available operations and objed-define-op to add your own.

|===

Misc commands:

[objed-map] |=== |Shortcut |Purpose

|kbd:[q] |Quit window or reformat in edit buffer.

|kbd:[u] |Pop to last state, which restores the last position and any object data.

|kbd:[z] |Choose an instance of current object type on the screen with avy (https://with-emacs.com/posts/objed/jump-around-emacs-version/[blog]).

|kbd:[M-g o] |Choose an instance of current object, by first lines content.

|kbd:[m] |Add/Remove current object to marked objects and move to next.

|kbd:[M] |Add/Remove current object to marked objects and move to previous.

|kbd:[@] |Activate region with current object (extend current object).

|kbd:[Ctrl - Space] |Set mark.

|kbd:[/] |Undo last edit command.

|kbd:[C-h b] |Get key binding help (uses which-key if available).

|kbd:[g/Ctrl - g] |Exit and deactivate objed. |===

Dispatch keys (dispatch to any object defined in objed-object-map). You can add your own prefix bindings using objed-define-dispatch.

[objed-map] |=== |Shortcut |Purpose

|kbd:[*] |Mark more instances of current object inside defun/buffer.

|kbd:[#] |Switch to another object using avy.

|kbd:[=] |Switch to another object inside the current one using avy.

|kbd:[`] |Activate part from point forward until boundary of some object.

|kbd:[´] |Activate part from point backward until boundary of some object.

|kbd:[+] |Extend current object by including trailing whitespace. |===

== Installation

Objed is on MELPA and GNU ELPA, for installation use:

M-x package-refresh-contents RET
M-x package-install RET objed RET
;; activate objed-mode in you init
(objed-mode)

For manual installation:

git clone http://github.com/clemera/objed.git

Add this to your init file:

(add-to-list 'load-path "/<path-to>/objed")
(require 'objed)
(objed-mode)
;; activating the mode is optional, you can activate objed
;; always manually using `objed-activate' the other
;; commands bound in `objed-mode-map`, for example:
;; (global-set-key (kbd "M-SPC") 'objed-activate)

In case you don't want to enable objed globally, use objed-local-mode:

(add-hook 'prog-mode-hook #'objed-local-mode)

== Contribute

I'm happy to receive pull requests or ideas to improve this package. Some parts suffer from the bottom up approach of developing it, but this also allowed me to experiment a lot and try ideas while working on them, something that Emacs is especially good at. Most of the features are tested using emacs-lisp-mode but hopefully there aren't to many problems using modes for other languages. Before submitting a PR please check your code compiles cleanly and all tests are passing:

make test

=== Copyright Assignment

This package is subject to the same https://www.gnu.org/prep/maintain/html_node/Copyright-Papers.html[Copyright Assignment] policy as Emacs itself, org-mode, CEDET and other packages in https://elpa.gnu.org/packages/[GNU ELPA].

Any https://www.gnu.org/prep/maintain/html_node/Legally-Significant.html#Legally-Significant[legally significant] contributions can only be accepted after the author has completed their paperwork. Please see https://git.savannah.gnu.org/cgit/gnulib.git/tree/doc/Copyright/request-assign.future[the request form] if you want to proceed with the assignment.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].