Git Product home page Git Product logo

emacs-sentence-navigation's Introduction

About http://melpa.org/packages/sentence-navigation-badge.svg

sentence-navigation.el is inspired by vim-textobj-sentence and uses a mostly the same default abbreviation list. It provides alternatives to forward-sentence, backward-sentence, and sentence text objects that work with sentences separated by one (or two) space(s) and is aware of abbreviations.

Installation

If you use MELPA, sentence-navigation.el can be installed with package-install. Here’s an example use-package configuration:

(use-package sentence-navigation
  :ensure t
  ;; autoloads will be created for all commands and text objects
  ;; when installed with package.el
  :defer t)

Example Configuration

There are no default key bindings. Unlike with the normal forward and backward sentence commands, these commands will move to the beginning or end of the sentence, not to the space in between.

Abbreviations

The list of abbreviations to ignore can be customized. The defaults are mostly the same as vim-textobj-sentence’s.

(setq sentence-nav-abbreviation-list
      '("[ABCDIMPSUabcdegimpsv]"
        "l[ab]" "[eRr]d" "Ph" "[Ccp]l" "[Ll]n" "[c]o"
        "[Oe]p" "[DJMSh]r" "[MVv]s" "[CFMPScfpw]t"
        "alt" "[Ee]tc" "div" "es[pt]" "[Ll]td" "min"
        "[MD]rs" "[Aa]pt" "[Aa]ve?" "[Ss]tr?" "e\\.g"
        "[Aa]ssn" "[Bb]lvd" "[Dd]ept" "incl" "Inst" "Prof" "Univ"))

If you change the abbreviation list after loading the package, you will need to run the following as well:

(sentence-nav-reload-abbreviations)

Evil

(define-key evil-normal-state-map ")" 'sentence-nav-evil-forward)
(define-key evil-normal-state-map "(" 'sentence-nav-evil-backward)
(define-key evil-operator-state-map ")" 'sentence-nav-evil-forward)
(define-key evil-operator-state-map "(" 'sentence-nav-evil-backward)
(define-key evil-normal-state-map "g)" 'sentence-nav-evil-forward-end)
(define-key evil-normal-state-map "g(" 'sentence-nav-evil-backward-end)
(define-key evil-outer-text-objects-map "s" 'sentence-nav-evil-outer-sentence)
(define-key evil-inner-text-objects-map "s" 'sentence-nav-evil-inner-sentence)

No Evil

(global-set-key (kbd "M-e") 'sentence-nav-forward)
(global-set-key (kbd "M-a") 'sentence-nav-backward)

Both sentence-nav-forward-end and sentence-nav-backward-end can also be bound.

Definition of a Sentence

Sentences start with a capital letter (possibly preceded some type of a left quotation mark). They end with a period (or other characters like “!”, “?”, or an ellipsis) possibly followed by some right quotation mark(s). In addition to quotes, org and markdown markup characters (such as _ and *) can be around sentences. Like with quotes, the point will be moved to just before or after the last surrounding markup character. Abbreviations are irrelevant for two-spaced sentences, and this plugin will work fine for them.

Impossible Cases

For the most part, this plugin can distinguish accurately between one-spaced sentences and abbreviations. In the rare case that a sentence actually does end in an abbreviation (not followed by “?”, “!”, etc.), this plugin will skip over that sentence. Because of this, I have removed the abbreviations “in” and “no” from vim-textobj-sentence’s list since I think a sentence is more likely to end in either “in” or “no” than for either to be used as an abbreviation.

Also, if hard line wrapping is being used, there is no way to distinguish between a sentence that starts at the beginning of the line and a capitalized word at the beginning of the line. It is possible to fix this for single-spaced hard-wrapped sentences by checking if the previous line ends in a period and not an abbreviation, but I haven’t bothered implementing this extra check for now at least.

Other Notes

Emacs doesn’t have support for negative look behind, so this uses looking-back. Emacs says this should be avoided because it is slow, but it works fine for this.

emacs-sentence-navigation's People

Contributors

noctuid avatar

Watchers

Sooheon Kim avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.