Giter Site home page Giter Site logo

fix-word's Introduction

Fix Word

License GPL 3 MELPA CI

This is a package that allows us to transform words intelligently. It provides the function fix-word that lifts functions that do string transformation into commands with interesting behavior. There are also some built-in commands built on top of fix-word.

Installation

The package is available via MELPA, so you can just type M-x package-install RET fix-word RET.

If you would like to install the package manually, download or clone it and put on Emacs' load-path. Then you can require it in your init file like this:

(require 'fix-word)

API description

fix-word fnc

Lift the function fnc into a command that operates on words and regions.

The following behaviors are implemented:

  1. If the point is placed outside of a word, apply fnc to the previous word. When the command is invoked repeatedly, every its invocation transforms one more word moving from right to left. For example (upcasing, ^ shows the position of the point):

    The quick brown fox jumps over the lazy dog.^
    The quick brown fox jumps over the lazy DOG.^
    The quick brown fox jumps over the LAZY DOG.^
    The quick brown fox jumps over THE LAZY DOG.^
    

    The point doesn't move, this allows us to fix recently entered words and continue typing.

  2. If the point is placed inside of a word, the entire word is transformed. The point is moved to the first character of the next word. This allows us to transform several words by invoking the command repeatedly.

    ^The quick brown fox jumps over the lazy dog.
    THE ^quick brown fox jumps over the lazy dog.
    THE QUICK ^brown fox jumps over the lazy dog.
    THE QUICK BROWN ^fox jumps over the lazy dog.
    
  3. If there is an active region, all words in that region are transformed.

Use fix-word to create new commands like this:

(defalias 'command-name (fix-word #'upcase)
  "Description of the command.")

There is also a macro that defines such commands for you: fix-word-define-command.


fix-word-define-command name fnc &optional doc

Define a fix-word-based command named name. fnc is the processing function and doc is the documentation string.

Built-in commands

The default commands to upcase/downcase/capitalize words are not convenient, for the following reasons:

  1. There are three different commands for upcaseing, for example. The user needs to remember the three commands, their key bindings, and when to use each of them. There should be one command per action: one for upcasing, one for downcasing, and one for capitalizing.

  2. The commands on regions don't have dedicated key bindings and are disabled by default.

  3. The commands like upcase-word depend on the position of pointer inside of the word, so that the result of upcasing "fo^o"is "foO". This packages assumes that you want "FOO".

  4. One needs to use arguments for commands like upcase-word to make them correct the words that one has just written and only one word can be adjusted in this way.

Here are the commands that try to fix these flaws:

  • fix-word-upcase
  • fix-word-downcase
  • fix-word-capitalize

I propose replacing of the built-ins with these new commands:

(global-set-key (kbd "M-u") #'fix-word-upcase)
(global-set-key (kbd "M-l") #'fix-word-downcase)
(global-set-key (kbd "M-c") #'fix-word-capitalize)

License

Copyright © 2015–present Mark Karpov

Distributed under GNU GPL, version 3.

fix-word's People

Contributors

akirak avatar dependabot[bot] avatar mrkkrp avatar purcell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

fix-word's Issues

How to correctly capitalize small words (a, an, the...) in the tittle.

According to this web site

All large words in the titles of movies, books, and other publications should be capitalized, while all small words (a, an, the, but, and, if, as, or, nor, to name a few) should not be capitalized unless they are the first or last words in the title:
A Life Less Ordinary (The word "A" would not normally be capitalized, but because it is the first word in the title, we must capitalize it.)
OR
War of the Worlds (The words "of" and "the" are not capitalized because they are small and are not at the beginning or end of the title, though exceptions to the "small words" rule do exist.)

So, how should we handle those scenarios when we capitalize words.

Bug when working backwards in multiple-cursors

This is a brilliant interface! Thanks for the great package.

It even works with multiple-cursors… except when extending backward. Not a deal-breaker as one can move the cursors to do it if need be, but thought I should record this bug.

Here's a demo of what happens with three lines, and three cursors at the start of 'over'.

The quick brown fox jumps ^over the lazy dog.
The quick brown fox jumps ^over the lazy dog.
The quick brown fox jumps ^over the lazy dog.

Then type this sequence:
M-u M-u M-u C-b

The quick brown fox jumps OVER THE LAZY^ dog.
The quick brown fox jumps OVER THE LAZY^ dog.
The quick brown fox jumps OVER THE LAZY^ dog.

M-l

The quick brown fox jumps OVER THE lazy^ dog.
The quick brown fox jumps OVER THE lazy^ dog.
The quick brown fox jumps OVER THE lazy^ dog.

M-l

The quick brown fox jumps OVER the lazy^ dog.
The quick brown fox jumps over THE lazy^ dog.
The quick brown fox jumps OVER THE lazy^ dog.

It looks to be caused by the use of fix-word--quick-fix-times as a global variable. Perhaps there would be a way to increment that count only once, or divide by the number of active cursors, or look into how smartparens handles sp--mc/cursor-specific-vars… haven't dug into this too much, as I said any case switching can be performed in other ways right now.

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.