emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using backticks for the inline code delimeter?


From: Tim Cross
Subject: Re: Using backticks for the inline code delimeter?
Date: Wed, 21 Apr 2021 08:30:08 +1000
User-agent: mu4e 1.5.11; emacs 28.0.50

Matt Price <moptop99@gmail.com> writes:

> On Wed., Mar. 31, 2021, 3:22 p.m. Timothy, <tecosaur@gmail.com> wrote:
>
>  autofrettage <autofrettage@protonmail.ch> writes:
>
>  > Quick and Dirty: Bind key '`' to ~ in Emacs?
>  >
>  > (I guess it is clear I haven't thought about the consequences.)
>
>  You can add that just to the Org-mode map. That wouldn't be too bad,
>  there's always C-q.
>
> Is it possible to bind a key in org-mode but bind it back to another 
> character if you're in a special environment, eg a code block? That would
> probably be my preference. So "`" inserts "~" when you're writing text but 
> "`" in an elisp or markdown SRC block, for instance. 
>
> I guess just write a function that checks context? Presumably all the 
> overloaded keybindings do this already but I guess I don't really know how 
> they
> do so. 
>

Yes, you can do that. However, results can vary. The 'bottleneck' is in
determining context. If that is easy, typically no problems. However, if
you need something complex or need to scan a large part of the buffer to
determine the context, then it can be problematic. 

> I do in general wish it were easier to switch between writing markdown and 
> writing org, since I often have to write markdown for work. 
>

Sounds like what you really need to do is define a set of key bindings
which use the same bindings in both org and markup modes (different
bound functions obviously). Instead of entering the character for 'code'
using org syntax when in org and markdown syntax when in markdown,
you just train your fingers to hit the key binding you have defined for
entering 'code'. One nice advantage of this approach is that you can
define functions such that if you hit that key binding it will insert
the mode specific character if no region is selected, but if a region is
selected, wrap that region using the nominated character. This is handy when
editing a document because if you come across a section and want to have
it rendered has code, bold, underlined etc, you can just select the
target region and hit the appropriate key and job done.

The other nice thing about this approach is you can generalise this
further to other modes, even HTML. You then think in terms of either
formatting or semantics (depending on how you define the bindings) and
not the lower level syntax. 

The challenge can be in identifying the most appropriate key bindings.
This can depend on the platform you use as well. When I was only using
Linux, I used the 'super' key for this and it was great. However, when I
also started using a mac, I had to define a new scheme. It can take a
bit of work to setup initially, but I think it is worth the effort. I
now have the same bindings in multiple modes, so regardless of whether
I'm writing markdown, org, html, rich text, etc, I just hit the same key
bindings to mark content as code, bold, italic, etc. 

-- 
Tim Cross



reply via email to

[Prev in Thread] Current Thread [Next in Thread]