2

In org-mode, writing a word wrapped by / makes it italic. For instance, /word/ becomes word.

Is there a command in Emacs to make something go from ẁord to /word/? Maybe some org related command only to do this?

2
  • 1
    The right way of implementing this would be to add this rule to org's syntax table I think. For example if you select a word in org mode and hit ", it will encircle it with the quotes. Take a look at `
    – aadcg
    Dec 8, 2021 at 20:35
  • 1
    AFAICT, this behavior of " and such is only available if you have enabled electric-pair-mode or its local equivalent.
    – NickD
    Dec 9, 2021 at 16:46

3 Answers 3

5

As usual, Org has you covered: org-emphasize, bound by default to C-c C-x C-f.

This will work for all emphasis markers. So, for italics, select the word and C-c C-x C-f /.

1
  • 1
    That's neat. In my humble opinion, the best answer.
    – aadcg
    Dec 10, 2021 at 1:35
1

The wrap-region package does this. You can install it from MELPA.

Once you have it installed, you can add wrappers for org:

(wrap-region-add-wrappers
 '(("*" "*" nil org-mode)
   ("/" "/" nil org-mode)
   ("~" "~" nil org-mode)
   ("+" "+" nil org-mode)))

You turn it on with M-x wrap-region-mode, or M-x wrap-region-global-mode if you want it for every buffer. Once it's on, if you select a word (or sentence or ...) and press one of the 'wrapper' keys, the characters will be added to the beginning and end of the active region. See the link above for details about customization for different modes.

1

When electric-pair-mode is on, the following syntax rule suffices:

(modify-syntax-entry ?/ "(/")

Notice that such rules should be added to org-mode only.

4
  • 3
    How exactly does this work? AFAICT, it does not for me, but I'm not sure what I am supposed to do. Can you explain? Do you have some sort of electric pair mode turned on? If so, your answer needs to be qualified.
    – NickD
    Dec 9, 2021 at 1:46
  • @NickD, thank you for your clarification. I've edited my answer.
    – aadcg
    Dec 9, 2021 at 22:35
  • 1
    I still think your second point is wrong: modifying the syntax table causes complaints about unbalanced parentheses when a / is typed, but there is no insertion of anything extra. Have you tried it with emacs -Q?
    – NickD
    Dec 10, 2021 at 5:01
  • 1
    You're correct. Edited again.
    – aadcg
    Dec 10, 2021 at 15:35

Your Answer

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

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