pangu-spacing
pangu-spacing copied to clipboard
Ignore link syntax in org-mode
When enable real-insert-space mode, we should ignore the link syntax in org-mode to prevent generated file error :(
+1 for this feature, it's very important when enable real-insert-space mode in org-mode links.
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
Hi @et2010 , your solution looks good to me. I'll close this issue after fix it. Thanks :)
That fix itself caused some more serious trouble! Luckily, after spending couple of hours googling, I finally came up with a good solution. :smile: