Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore link syntax in org-mode #10

Open
coldnew opened this issue Mar 23, 2015 · 4 comments
Open

Ignore link syntax in org-mode #10

coldnew opened this issue Mar 23, 2015 · 4 comments

Comments

@coldnew
Copy link
Owner

coldnew commented Mar 23, 2015

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

@zilongshanren
Copy link

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

@et2010
Copy link

et2010 commented Feb 14, 2016

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@28c049c

@coldnew
Copy link
Owner Author

coldnew commented Feb 15, 2016

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

et2010 referenced this issue in et2010/Han Feb 15, 2016
Last commit will cause some serious issue. While saving buffer, some
text will be replaced randomly. I believe it is due to org's parsing
mechanism which will change match data during parsing. It is fixed now,
by some save-match-data magic.
@et2010
Copy link

et2010 commented Feb 15, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants