Sublime Forum

Typography

#1

Hello,

I’m looking for suggestion to make writing blog posts for Nikola static-site-generator using Asciidoc(tor) markup…In Emacs I was using typoel package which provides

“…buffer-specific minor mode that will change a number of normal keys to make them insert typographically useful unicode characters. Some of those keys can be used repeatedly to cycle through variations. This includes in particular quotation marks and dashes.”

For Quotes it works like this:

"All quotation marks… are added by hitting the " key exactly once each. typo.el guessed the correct glyphs to use from context. If it gets it wrong, you can just repeat hitting the " key until you get the quotation mark you wanted.

For Dashes and Dots:

"The hyphen key will insert a default hyphen-minus glyph. On repeated use, though, it will cycle through the en-dash, em-dash, and a number of other dash-like glyphs available in Unicode. This means that typing two dashes inserts an en-dash and typing three dashes inserts an em-dash, as would be expected. The name of the currently inserted dash is shown in the minibuffer.

The full stop key will self-insert as usual. When three dots are inserted in a row, though, they are replaced by a horizontal ellipsis glyph."

I’m wonder if something like this would be possible to have for ST3?

The best thing which I’ve found so far is TypeSnippets, but it’s a bit cumbersome, e.g. in order to enter “…” one has to type ‘doublequotes’ etc.

Moreover, it’s problematic when one wants e.g. to enter ‘…’, since one has to type ‘ellipsis’, and one has to enter space before typing ‘ellipsis’ and then to remove that space if ellipsis are to be following the word…

1 Like

#2

Yes, this is possible (and even easier to archive as in Emacs, because of the way you define keybindings and contexts)

I even made a package for the quotation marks, but it only works in LaTeX: LaTeXSmartQuotes. If there is a demand for it I may also enable it in other languages.

The other thing can also relativly easy archived by a plugin if you have the definitions which key sequence should be replaced by what. If you only have a few sequences you can even write it without programming only in the keybindings.
The following requires the Package “Chain of Commands” to be installed, replaces “…” by “…” (unicode) and undoes the conversion with backspace:

    {
        "keys": ["."],
        "command": "chain",
        "args": {
            "commands": [
                ["left_delete"],
                ["left_delete"],
                ["insert", {"characters": "…"}]
            ]
        },
        "context":
        [
            { "key": "preceding_text", "operator": "regex_contains", "operand": "\\.\\.$" },
            // maybe limit it to a language
        ],
    },
    {
        "keys": ["backspace"],
        "command": "chain",
        "args": {
            "commands": [
                ["left_delete"],
                ["insert", {"characters": "..."}]
            ]
        },
        "context":
        [
            { "key": "preceding_text", "operator": "regex_contains", "operand": "…$" },
            // maybe limit it to a language
        ],
    },
3 Likes

#3

That’s nice to hear…I’m still finding my way with ST3. :wink:

[quote]I even made a package for the quotation marks, but it only works in LaTeX: LaTeXSmartQuotes. If there is a demand for it I may also enable it in other languages.
[/quote]

I certainly consider that such package would be useful for many types of text which is not a code, like rst, markdown, asciidoc etc.

I’ll take a look…

Moreover, it would be nice if your package would support some other common things like ellipsis, em/en-dashes etc. :wink:

0 Likes

#4

That’s not common in LaTeX :wink: so I am not going to add it to the package. I would rather write an extra package for that (and maybe also the quotations).

0 Likes

#5

No objections here. :wink:

0 Likes

#6

@gour
Would you be willing to write a definition of replacements like this and publish the package together:

{
    "...": "…",
    "--": "–",  # ndash
    "–-": "—",  # mdash
    "->": "→",
    "→>": "↠",
    "–>": "⟶",
}

I made a small proof-of-concept and it looks quite promising:

2 Likes

#7

You mean for all the required/desired combinations as in the 1st example above?

I’ll do, just need some time since soon I’m going out…but count on me. :wink:

0 Likes

#8

Sounds interesting. I know this feature from Microsoft Office and found it useful in some situations, too.

0 Likes

#9

@gour
Yes it will be similar to this, but maybe an other format (e.g. an array of 2-tuples to support multiple triggers and maybe yaml instead of json). In addition I think it will automatically expand the keys, so that you just write "->": "→", "->>": "↠" instead of "->": "→", "→>": "↠" and it will automatically converted.

As soon I have a good name for package I can host the first alpha version on github.

0 Likes