Skip to content

Commit

Permalink
org-mode: Fix '*' for creating section head
Browse files Browse the repository at this point in the history
  • Loading branch information
xwl committed Nov 6, 2021
1 parent 859f4ab commit ed77bc8
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions electric-spacing-org-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,25 @@

(defun electric-spacing-org-mode-inline-marker (op)
"For inserting inline markers, like *bold* or /italic/."
(let ((line (buffer-substring-no-properties (line-beginning-position) (point))))
(if (zerop (% (count (string-to-char op) line) 2))
(electric-spacing-insert op 'before)
(electric-spacing-insert op 'after))))
;; headline
(if (looking-back (format "^ +\\|^\\%s+ *" op) (line-beginning-position))
(electric-spacing-insert op 'after)
;; pairs like emphasize mark
(let ((prev (save-excursion
(when (search-backward op (line-beginning-position) t 1)
(point)))))
(catch 'exit
(when prev
(let (emphasize-start)
(save-excursion
(goto-char prev)
(setq emphasize-start (looking-back " "))
(goto-char (1+ prev))
(setq emphasize-start (and emphasize-start (not (looking-at " ")))))
(when emphasize-start
(electric-spacing-insert op 'after)
(throw 'exit))))
(electric-spacing-insert op 'before)))))

(defun electric-spacing-org-mode-* ()
(electric-spacing-org-mode-inline-marker "*"))
Expand Down

0 comments on commit ed77bc8

Please sign in to comment.