Coder Social home page Coder Social logo

parallel's Introduction

parallel

Coverage Status

parallel allows you to create a command comprising two commands. The first function, the default, consumes normal prefix arguments, the second requires a numeric argument to activate and consumes numeric prefix arguments.

It grew out of my configuration and therefore is currently still heavily geared towards my usage.

Installation

If you use straight or quelpa, you know what to do.

If you’re on Emacs >29, I recommend using package-vc-install.

Alternatively, provided you have Cask, you can install the package with make package-install.

Usage

Say you have two related commands but too many key-bindings already. You also want those two commands do consume prefix arguments.

(require 'parallel)

(defun say-yes (&optional no)
  "Say 'yes', unless NO is t, then say 'no'."
  (interactive "P")

  (if no
      (message "no")
    (message "yes")))

(defun say-hello (&optional goodbye)
  "Say 'hello', unless GOODBYE is t, then say 'goodbye'."
  (interactive "P")

  (if goodbye
      (message "goodbye")
    (message "hello")))

(parallel say-yes say-hello)

This will create a new command say-yes||hello. Let’s take a look at the docstring:

;; Call `say-yes' or `say-hello' depending on prefix argument.

;; No argument means: call the prior. Numeric prefix 0 means: call the latter.

;; For all other prefix values: numeric prefixes call the latter,
;; `universal-argument' prefixes call the prior.

If you bind this command now, it will call say-yes and call message with “yes”. If you call it with the universal-argument, it will branch as expected and call message with “no”.

If you want to call say-hello, you need to call the new command with a numeric prefix argument. C-u 0 will call say-hello normally as if no prefix argument had been provided, and will call message with “hello”; all other numeric prefix arguments will be passed and therefore the function will call message with “goodbye= for C-u 1, for example.

If you need your second command to sometimes behave like a normal command because it uses the prefix argument to branch (take a look at org-refile for example), you can pass the key :universalize t.

(parallel say-yes say-hello :universalize t)

This means that a C-u 4 for example will result in prefix argument =’(4)= like a normal C-u would.

Configuration

You can configure the separator used to construct the new command name by setting parallel-separator. The default is the string =”||”=.

If you want to avoid automatic normalizing you can set parallel-naming-function to parallel--concatenate or your own function accepting the two function symbols to return a new symbol.

(setq parallel-naming-function 'parallel--concatenate)

(parallel say-yes say-hello) ;; Now creates command `say-yes||say-hello'.

If you have a custom namespace for your functions, say my/, you can set parallel-custom-namespace to =”my/”= to ensure normalizing works.

(parallel my/say-hello say-yes) ;; Would yield `my/say-hello||say-yes'.

(setq parallel-custom-namespace "my/")

(parallel my/say-hello say-yes) ;; Now yields expected `say-hello||say-yes'.

parallel's People

Contributors

walheimat avatar semantic-release-bot avatar

Stargazers

 avatar

Watchers

 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.