GithubHelp home page GithubHelp logo

emacsmirror / aas Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ymarco/auto-activating-snippets

0.0 2.0 0.0 108 KB

Snippet expansions mid-typing

Home Page: https://github.com/ymarco/auto-activating-snippets

License: GNU General Public License v3.0

Emacs Lisp 100.00%

aas's Introduction

Auto Activating Snippets

This package implements an engine for auto-expanding snippets. It is done by tracking your inputted chars along a tree until you complete a registered key sequence.

Its like running a long prefix command, but the keys you type are not ‘consumed’ and appear in the buffer until you complete the whole command - and then the snippet is triggered!

Usage & Basic Configuration

We didn’t implement a complex file type like yasnippet. Declare your snippets with aas-set-snippets straight away, using :cond to set conditions.

Example configuration using use-package:

(use-package aas
  :hook (LaTeX-mode . aas-activate-for-major-mode)
  :hook (org-mode . aas-activate-for-major-mode)
  :config
  (aas-set-snippets 'text-mode
    ;; expand unconditionally
    ";o-" "ō"
    ";i-" "ī"
    ";a-" "ā"
    ";u-" "ū"
    ";e-" "ē")
  (aas-set-snippets 'latex-mode
    ;; set condition!
    :cond #'texmathp ; expand only while in math
    "supp" "\\supp"
    "On" "O(n)"
    "O1" "O(1)"
    "Olog" "O(\\log n)"
    "Olon" "O(n \\log n)"
    ;; Use YAS/Tempel snippets with ease!
    "amin" '(yas "\\argmin_{$1}") ; YASnippet snippet shorthand form
    "amax" '(tempel "\\argmax_{" p "}") ; Tempel snippet shorthand form
    ;; bind to functions!
    ";ig" #'insert-register
    ";call-sin"
    (lambda (angle) ; Get as fancy as you like
      (interactive "sAngle: ")
      (insert (format "%s" (sin (string-to-number angle))))))
  ;; disable snippets by redefining them with a nil expansion
  (aas-set-snippets 'latex-mode
    "supp" nil))

There’s also aas-global-mode which activates snippets from the keymap global, e.g

(aas-set-snippets 'global
  ";--" ""
  ";->" "")
(aas-global-mode)

(If you want more LaTeX snippets, take a look at LaTeX-auto-activating-snippets)

Comparison to other snippet engines

UltiSnips does its automatic expansion by matching regexes on the current line. We do it by tracking the last characters you typed. This means that if you have a snippet expanding sin to \sin but you typed s e ←backspace i n, the snippet wont expand because the mistyped key broke the sequence. It does mean though that having many many snippets shouldn’t impact performance (just like having big keymaps doesn’t).

Yasnippet can auto-expand snippets, but that method is expansive with a large number of snippets - it calls all the conditions of all the snippets after each expansion trial. But no reason to carry on using it for only a few snippets if you already have it set up!

(I also learned of that method only after writing this engine.)

cdlatex requires you to have 1 or 2 keys sacrificed (usually ` for mathematical symbols and ~’~ for accents) in order to trigger its entry functions and expand a snippet. This package can ‘emulate’ cdlatex entirely, while not sacrificing any input keys! If you have a snippet with the key `a, you can type ` as much as you want and as long as an a doesn’t follow nothing unusual would happen. Many of the snippets in LaTeX-auto-activating-snippets were ‘inspired’ by cdlatex, replacing ` as a prefix by ;.

aas's People

Contributors

hyunggyujang avatar syohex avatar tecosaur avatar ymarco avatar

Watchers

 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.