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

Do not write real space in special region in org-mode #37

Merged
merged 1 commit into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions pangu-spacing.el
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,33 @@ pangu-sapce-mode."
`(pangu-spacing-search-buffer ,regexp ,beg ,end
(,func (match-beginning 1) (match-end 1))))

(defun pangu-spacing-org-mode-at-special-region ()
(interactive)
(let ((element (org-element-at-point)))
(when (or (member (org-element-type element)
'(src-block keyword example-block export-block
latex-environment planning))
(member (car (org-element-context element))
'(inline-src-block timestamp link code verbatim)))
t)))

(defcustom pangu-spacing-special-region-func-alist
'((org-mode . pangu-spacing-org-mode-at-special-region))
"Alist mapping major-mode to the corresponding function to
check for special region that shall not write real pangu-space"
:group 'pangu-spacing
:type '(alist :key-type (symbol)
:value-type (function)))

(defun pangu-spacing-search-and-replace (match regexp)
"Replace regexp with match in buffer."
(pangu-spacing-search-buffer regexp (point-min) (point-max)
(replace-match match nil nil)))
(let ((at-special-region-func
(cdr (assq major-mode pangu-spacing-special-region-func-alist))))
(pangu-spacing-search-buffer
regexp (point-min) (point-max)
(unless (and at-special-region-func
(save-match-data (funcall at-special-region-func)))
(replace-match match nil nil)))))

(defun pangu-spacing-overlay-p (ov)
"Determine whether overlay OV was created by space-between."
Expand Down
34 changes: 34 additions & 0 deletions test/pangu-spacing-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,40 @@
)
)

(ert-deftest pangu-spacing-test/org-mode-special-region ()
(with-temp-buffer
(insert "* English中文English [[https://github.com/][link中文link]]
CLOSED: [2018-10-14日21:42]
- State \"DONE\" from \"TODO\" [2018-10-14日21:42]
[2018-09-17一]
English中文English
* ~English中文English~
<2018-09-17一>
=/home/me/English中文English.conf=
#+BEGIN_SRC conf :tangle English中文English.conf
English中文English
#+END_SRC")
(message "1")
(pangu-spacing-mode 1)
(message "2")
(org-mode)
(message "3")
(let ((pangu-spacing-real-insert-separtor t))
(pangu-spacing-modify-buffer))
(message "4")
(should (string-equal (buffer-string)
"* English 中文 English [[https://github.com/][link中文link]]
CLOSED: [2018-10-14日21:42]
- State \"DONE\" from \"TODO\" [2018-10-14日21:42]
[2018-09-17一]
English 中文 English
* ~English中文English~
<2018-09-17一>
=/home/me/English中文English.conf=
#+BEGIN_SRC conf :tangle English中文English.conf
English中文English
#+END_SRC"))))

(ert-deftest pangu-spacing-test/show ()
"Test if showing works"
(with-temp-buffer
Expand Down