pangu-spacing icon indicating copy to clipboard operation
pangu-spacing copied to clipboard

Ignore link syntax in org-mode

Open coldnew opened this issue 9 years ago • 4 comments

When enable real-insert-space mode, we should ignore the link syntax in org-mode to prevent generated file error :(

coldnew avatar Mar 23 '15 02:03 coldnew

+1 for this feature, it's very important when enable real-insert-space mode in org-mode links.

zilongshanren avatar Aug 01 '15 07:08 zilongshanren

I found a way to solve this issue. But I'm not sure whether it's a good idea to raise a PR here since it's an ad hoc solution relying on org-element.el. The fix itself is pretty straightforward. It advises pangu-spacing-search-and-replace function to act like this: During the search and replace process, it will check whether the match-beginning or match-end point is in an org-link element, if true then it will skip replacing the match, otherwise it will do the replace as usual. Here is the code:

(with-eval-after-load "org-element"
  (defadvice pangu-spacing-search-and-replace (around pangu-spacing-org-link-fix activate)
    "Replace regexp with match in buffer."
    (if (eq 'org-mode (buffer-local-value 'major-mode (current-buffer)))
        (pangu-spacing-search-buffer regexp (point-min) (point-max)
                                     (if (member 'link
                                                 (mapcar
                                                  (lambda (point)
                                                    (save-excursion
                                                      (goto-char point)
                                                      (org-element-type (org-element-context))))
                                                  (list (match-beginning 0) (match-end 0))))
                                         (goto-char (match-end 0))
                                       (replace-match match nil nil)))
      ad-do-it)))

If you are a spacemacs user, you can also check on my private layer et2010/Han@28c049c26c870e5cb5ea96cba846e58ae4af8759

et2010 avatar Feb 14 '16 05:02 et2010

Hi @et2010 , your solution looks good to me. I'll close this issue after fix it. Thanks :)

coldnew avatar Feb 15 '16 01:02 coldnew

That fix itself caused some more serious trouble! Luckily, after spending couple of hours googling, I finally came up with a good solution. :smile:

et2010 avatar Feb 15 '16 15:02 et2010