0

I have a problem when I want to yas-expand a link in Org-mode and it has a dash (-) in the text (url and description). Then the snippet break and exits. If I do the same in fundamental-mode it works.

Example

Typing text in fundamental and Org-mode. In fundamental mode:

"jira<tab>abc-123" ->
[[https://jira.example.com/browse/ABC-123][ABC-123]]

In Org-mode:

"jira<tab>abc-123" ->
[[https://jira.example.com/browse/ABC-][ABC-]]123

In fundamental-mode I can tab to the last position. But in Org-mode it exits before that.

Snippet

The snippet looks like this:

# -*- mode: snippet -*-
# name: jira
# key: jira
# --
[[https://jira.example.com/browse/${1:$$(upcase yas-text)}][$1]]$0

Emacs Config

I have this config:

(use-package yasnippet
  :ensure t
  :config (yas-global-mode))

Full source for this (my emacs testing area): Source

If I change the snippet and remove the last "]", it works again but without becoming a link.

From: [[${1:$$(upcase yas-text)}][$1]]$0
To:   [[${1:$$(upcase yas-text)}][$1]$0

So it has something todo with org-insert-link but I cannot find out if this belongs to yas or org. Maybe there is a workaround for this. Any ideas how to troubleshoot or fix this?

Versions

yasnippet-20181015.1212
Org mode version 9.1.9 (release_9.1.9-65-g5e4542 @ /usr/share/emacs/27.0.50/lisp/org/)
GNU Emacs 27.0.50 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.22.30) of 2019-03-04

2 Answers 2

0

You can make the closing bracket be the last element in your template. This avoids your input from becoming a link before you finish typing:

[[https://jira.example.com/browse/${1:$$(upcase yas-text)}][$1]${0:$$(insert "]")}
1
  • OK, this did solve my issue. Still a bit curious why this was needed though. What causes the different expansions? But that is maybe something I should post to yas on github.
    – sdaaish
    Commented Apr 23, 2019 at 21:03
0

[[link][description]] syntax will only be shown as description in org-mode, which messed up with the yasnippet placeholder. You can manually switch it to plain text by calling M-x org-toggle-pretty-entities, and then yas-expand your snippet. You will then find it work well.

I didn't dig into the yasnippet code, so I can only offer a temporary dirty solution. Turn off org-mode font-lock before expansion, and turn it on again after expansion by adding org-toggle-pretty-entities to yasnippet builtin yas-before-expand-snippet-hook and yas-after-expand-snippet-hook.

(add-hook 'yas-before-expand-snippet-hook 'org-toggle-pretty-entities)
(add-hook 'yas-after-expand-snippet-hook 'org-toggle-pretty-entities)

Maybe you can issue a bug on github.

1
  • I don't think this has to do with org-toggle-pretty-entities. I tested your solution but there is no difference. What I'm trying todo is to upcase the URL and description. I like to write the case-number manually sometimes. But cut&paste is always an option. So maybe this is a bug, have not written a more advanced snippet before. I checked view-lossage and the difference between fundamental or text-mode and org-mode is that the former uses self-insert-command and org uses org-self-insert-command. So I will probably create an issue on yasnippet for this.
    – sdaaish
    Commented Mar 7, 2019 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.