6

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?

  • 2
    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 ... – lawlist Nov 9 '17 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. – Felix Z. Hoffmann Nov 12 '17 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. – Tobias Jul 21 '18 at 14:21
2

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!")
      )
    )
    )
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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