分享两个好用的 sis inline mode 相关的配置

退出 inline 模式后如果输入中文标点,自动去掉一个空格:

(defvar-local +sis-inline-english-last-space-pos nil
    "The last space position in inline mode.")

  (add-hook! sis-inline-english-deactivated-hook
    (defun +sis-line-set-last-space-pos ()
      (when (eq (char-before) ?\s)
        (setq +sis-inline-english-last-space-pos (point)))))

  (add-hook! sis-inline-mode-hook
    (defun +sis-inline-add-post-self-insert-hook ()
      (add-hook! post-self-insert-hook :local
        (defun +sis-inline-remove-redundant-space ()
          (when (and (eq +sis-inline-english-last-space-pos (1- (point)))
                     (looking-back " [,。?!;:]"))
            (save-excursion
              (backward-char 2)
              (delete-char 1)
              (setq-local +sis-inline-english-last-space-pos nil)
            ))
          ))
      ))

退出 inline 模式时如果首部空格前是中文标点,自动去掉空格:

(defun +sis-remove-head-space-after-cc-punc (tighten-fore-to)
    (when (memq (char-before) '(?, ?。 ?? ?! ?; ?:))
      (delete-char 1)))
  (setq sis-inline-tighten-head-rule #'+sis-remove-head-space-after-cc-punc)

用之前记得更新 sis,第二个配置需要我今天被合入的 PR 才能使用

3 个赞

防止在部分模式下频繁触发检查:

(defadvice! +sis-context-guess-ignore-modes (fn &rest args)
    :around #'sis--context-guess
    (if (derived-mode-p 'pdf-view-mode)
        'english
      (apply fn args)))
2 个赞