20

Given a region or line of text in org-mode I would like to call a function that either strikes-through the region or removes the strike-through of the region or line if strike-through is already present.

C-c C-x C-f + does not seem to do the trick, as for proper strike-through display in my org-mode version, each line must be wrapped with "+" individually.

How can I define a function that works like comment-or-uncomment-region for strike-through in org-mode?

3
  • 4
    If I understand the question correctly, you essentially want to add or remove a + at region-beginning and region-end when the region is active; and, for it to be a little smart as to whether + indicators are already present. This does not need to be org-mode specific and can be done with just a few lines of code, but there may be an existing function. Inasmuch as org-mode is under constant development, I tend not to answer a moving target ... An org-mode guru familiar with the latest build and previous builds should be along shortly ... Commented Nov 9, 2017 at 20:09
  • @lawlist Yes, I agree, this does not need to be org-mode specific. However, it's important that each line in the region is enclosed by + as only then strike-through properly renders in org-mode. Commented Nov 12, 2017 at 10:19
  • @FelixZ.Hoffmann The implementation of org-emphasize is quite naive in orgmode 9.1.6. Please note that the line-wise strike-through version is also not working in all circumstances. It breaks headlines and tables within the region to be striken-through. Commented Jul 21, 2018 at 14:21

3 Answers 3

10

This post asked the question long time ago, but as of today and speaking of org-mode version 9.5.4, the strikethrough feature has already been integrated into org-emphasize function. See f1+v describe variable and look for org-emphasize-alist you are going to see all the markings and strikethrough can be invoked by pressing + after the C-c C-x C-f keystroke (which invokes the org-emphasize function).

0
5

If you're still looking for the solution,

I've made a partial solution for this

check this out (copied from https://emacs.stackexchange.com/a/45848/18252):

 (defun strike-through-for-org-mode () (interactive) (beginning-of-line) (save-excursion (if (string-prefix-p "*" (thing-at-point 'line t)) (progn (setq go_char (string-match "[ ]" (thing-at-point 'line t))) (forward-char (+ go_char 1)) (insert "+") (end-of-line) (insert "+") ) (if (string-match "[^ ]" (thing-at-point 'line t)) (progn (setq go_char (string-match "[^ ]" (thing-at-point 'line t))) (forward-char (+ go_char 2)) (insert "+") (end-of-line) (insert "+") ) (message "[-] Not Proper Position!") ) ) ) ) 

(defun strike-through-for-org-mode-undo () (interactive) (beginning-of-line) (save-excursion (if (string-match "[+]" (thing-at-point 'line t)) (progn (setq go_char (string-match "[+]" (thing-at-point 'line t))) (forward-char go_char) (delete-char 1) (end-of-line) (delete-char -1) ) (message "[-] Not Proper Position!") ) ) ) 
0
5

For visitors who use Evil: you can use the evil-surround minor mode to deal with various kinds of markup, including plus signs for strike-through. Evil makes it quite convenient to work on the level of the visual-mode selection, lines or words. (I'm handling one line at a time, so not sure yet if there's support for identical normal-mode operations on multiple lines.)

However, to delete the plus-sign markers, you'll need to add them to Evil as text objects.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.