Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Navigate and edit text objects with Emacs. Development on pause.

License

NotificationsYou must be signed in to change notification settings

clemera/objed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GNU ELPAMELPA StableMELPA

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 enablesmodal editing and composition of commands. It combines ideas ofversor-mode and other Editors like Vimor Kakoune and tries to align them with regular Emacs conventions.

For more information you can read myposts aboutobjed and forchanges check theNewsfile.

Introduction

Text objects are textual patterns like a line, a top level definition, a word,a sentence or any other unit of text. Whenobjed-mode orobjed-local-modeis enabled, certain editing commands (configurable) will activateobjed andenable its modal editing features. When active, keys which would usually inserta character are mapped to objed commands. Other keys and commands will continueto work as they normally would and exit this editing state again.

By default important editing keys likeSpace,DEL orReturnare not bound to modal commands and will execute the regular command and exitobjed. Character movement exitsobjed, as well. This makes it convenientto move around and continue by adding/deleting text.

With activationobjed shows the current object type in themode-line. Thetextual content of the object is highlighted visually in the buffer and thecursor color is changed, too. The user can now navigate by units of thisobject, change the object state or switch to other object types.

The object state is eitherinner orwhole and is indicated in the modelineby(i) or(w) after the object type. With inner state, anything that wouldbe considered delimiters or padding around an object is excluded.

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

The object type used for initialization is determined by theentry command (seeobjed-cmd-alist). For example, usingbeginning-of-defunwill activateobjed using thedefun object as an initial object type. Withthe commandnext-line,objed would initialize with theline object. Toactivateobjed without movement you can useobjed-activate, bound toM-SPC by default. Objed uses the last command and its mapping inobjed-command-alist to choose the initial object.

Objed’s modal state provides basic movement commands which move by line, sexpword or character. Those commands automatically activate the corresponding objecttype. Other commands only activate the part between the initial position andthe new position moved to. By repeating commands you can often expand/proceedto other objects. This way you can compose movement and editing operationsvery efficiently.

The expansion commands distinguish between block objects (objects built out oflines of text like paragraphs or text blocks with the same level ofindentation and also comment blocks) and context objects (programmingconstructs like strings, brackets, comments or functions). This way you canquickly expand to the desired objects.

For example to move to the end of the paragraph, the user would first move tothe end of the line withCtrl - e. This would activateobjed using theline object with the text moved over. The user can now continue to the end ofthe paragraph by pressinge again. Now s?he is able to proceed evenfurther by pressinge again OR to continue by adding new text to the endof the paragraph OR to continue by acting on the text moved over, for examplekilling it by pressingk.

As often with text editing, the explanation sounds more complicated than usingit. To get a better impression of the editing workflow withobjed I haveadded some animated demos below.

To learn more about available features and commands have a look at thedescriptions below, the commentary section or the docstrings and bindingsdefined inobjed-map. To define your own operations and text objects seeobjed-define-op andobjed-define-object.

Examples of usage

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

Object navigation
Figure 1. Object navigation

Object expansion
Figure 2. Object expansion

End of block expansion
Figure 3. End of block expansion

Upto context
Figure 4. Upto context

Marking objects and act on them
Figure 5. Marking objects and act on them

Mark objects inside another one
Figure 6. Mark objects inside another one

Select current object type with avy
Figure 7. Select current object type with avy

Navigate and search output object
Figure 8. Navigate and search output object

Keys

Although some features are still experimental the basic user interface willstay 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 ofCtrl orMeta.0 can be used as an alternative for theuniversal argument (C-u). To add custom commands to the modal state youcan useobjed-user-map which is available under prefix key' andobjed-other-user-map bound to-. It’s recommended to use one of thesemap for custom object bindings and the other one for additional operations.

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

In addition to the commands configured inobjed-cmd-alist you can use thefollowing commands to enter objed (those bindings are only active if you areusingobjed-mode, if you choose to activate objed always manually you haveto bind those commands in yourglobal-map):

[objed-mode-map]

ShortcutPurpose

M-SPC

Activate objed, choosing initial object based onlast-command andobjed-cmd-alist.

M-#

Choose an object and activate with it.

C-+/C-.

Move to previous/next identifier and activateidentifier object.

M-[

Activate object at point (determined from context) and move to its start.

M-]

Activate object at point (determined from context) and move to its end.

M-(

Move to beginning of object at point and active text moved over.

M-)

Move to end of object at point and active text moved over.

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

[objed-map]

ShortcutPurpose

l/h

Move forward/backward one char and activate the char object

f/b

Move forward/backward one sexp and activate the sexp object

s/r

Move forward/backward one word and activate the word object.

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]

ShortcutPurpose

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.

a

Move to beginning of line and activate the text moved over. On repeat proceed to beginning of blocks like explained above.

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 constructslike defuns, strings, parentheses but also sentences inside comments forexample. Any whitespace after point is skipped before determining the context:

[objed-map]

ShortcutPurpose

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.

j

Move point to the other side of the current object.

t

Toggle object state. Switches between inner and whole object state.

[/]

Move to the start of previous/next instance of current object type.

(/)

Move to inner beginning/end of the object at point and activate the text moved over.

{/}

Move forward/backward paragraph and switch to paragraph object

</>

Goto first/last instance of current object type (blog).

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

[objed-map]

Shortcut

Purpose

.

Switch to identifier object or move to next.

,

Switch to identifier object and move to previous.

c

Prefix to switch to other objects, seeobjed-object-map for available objects andobjed-define-object to add your own (blog).

Indent/Move objects around:

[objed-map]

ShortcutPurpose

C-left/C-right

Move/indent all lines in object right/leftward.

M-left/M-right

Move/indent all lines in object to right/leftward to tab stop.

C-M-left/C-M-right

Slurp following sexp into current object/Barf last sexp out of current object.

S-left/S-right/S-up/S-down/F/B

Move current object type forward/backward (blog).

L/H

Switch to char object and move it forward/backward.

S/R

Switch to word object and move it forward/backward.

N/P

Switch to line object and move it forward/backward.

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

[objed-map]

ShortcutPurpose

i

Delete current object(s) and switch to insert.

k

Kill current object(s). Continues by selecting the next instance from point.

K

Kill current object. Continues by selecting the previous instance from point.

d

Delete current object(s). Continues by selecting the next instance from point.

D

Delete current object. Continues by selecting the previous instance from point.

w

Copy current object(s). On repeat move to next and append it tokill-ring

y

Yank last killed text at point. On repeat, cycle throughkill-ring

\

Indent object(s).

;

Un/comment object(s).

%

Query replace narrowed to current object.

^

Replace object with inner part (raise).

!

Run object contents as shell commands.

&

Pipe object region through shell command.

|

Incrementally construct command chain to replace text (blog).

Ctrl - RET

Evaluate current object in REPL (needeval-in-repl to be installed).

M - RET

Duplicate object.

S - RET

Comment and duplicate object.

C - M - RET

Insert new (empty) instance of current object type. This inserts the object boundaries without the inner content.

$

Spell check textual content of object usingflyspell.

~

Undo in current object region.

"

Add surroundings to object(s) with any pair usingelectric (built-in).

x

Prefix to access other operations, seeobjed-op-map for available operations andobjed-define-op to add your own.

Misc commands:

[objed-map]

ShortcutPurpose

q

Quit window or reformat in edit buffer.

u

Pop to last state, which restores the last position and any object data.

z

Choose an instance of current object type on the screen withavy (blog).

M-g o

Choose an instance of current object, by first lines content.

m

Add/Remove current object to marked objects and move to next.

M

Add/Remove current object to marked objects and move to previous.

@

Activate region with current object (extend current object).

Ctrl - Space

Set mark.

/

Undo last edit command.

C-h b

Get key binding help (useswhich-key if available).

g/Ctrl - g

Exit and deactivateobjed.

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

[objed-map]

ShortcutPurpose

*

Mark more instances of current object inside defun/buffer.

#

Switch to another object usingavy.

=

Switch to another object inside the current one usingavy.

`

Activate part from point forward until boundary of some object.

´

Activate part from point backward until boundary of some object.

+

Extend current object by including trailing whitespace.

Installation

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

M-x package-refresh-contents RETM-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 enableobjed globally, useobjed-local-mode:

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

Contribute

I’m happy to receive pull requests or ideas to improve this package. Someparts suffer from the bottom up approach of developing it, but this alsoallowed me to experiment a lot and try ideas while working on them, somethingthat Emacs is especially good at. Most of the features are tested usingemacs-lisp-mode but hopefully there aren’t to many problems using modes forother languages. Before submitting a PR please check your code compilescleanly and all tests are passing:

maketest

Copyright Assignment

This package is subject to the sameCopyright Assignmentpolicy as Emacs itself, org-mode, CEDET and other packages inGNU ELPA.

Anylegally significantcontributions can only be accepted after the author has completedtheir paperwork. Please seethe request formif you want to proceed with the assignment.

About

Navigate and edit text objects with Emacs. Development on pause.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp