无论是 ParEdit 还是 Smartparens 都很难用啊


#22

前面 11# 楼通过判断 font-lock-keyword-face 来决定是否在 ( 前面加空格的方式存在一个“例外”:sizeof

c 语言中的 sizeof 确实是关键字,但它写起来很像函数。

要不要忍受这个“例外”看着办吧。


#23

不太理解,为何要在非lisp环境下使用ParEdit。。。


#24

即使在非 lisp 环境,大部分情况下它都工作得很好,少数情况自己做点修补就可以了。


#25

我觉得你要求太高了点,其实这个功能针对sexp风格的lisp系语言。至于用于别的,只是个微微的扩展,毕竟语言的不同在哪里。它本应该只支持lisp系的,现在这点点扩展搞的大家心里痒痒的不爽


#26

求您的这个hydra小抄?谢谢! 很漂亮,想直接抄过来,伸手党见笑了08


#27
(defhydra hydra-paredit-cursor (:hint nil)
  "
^<< up >>^              ^<< backword^           ^forward >>^            ^<< down >>^
^^^^^^^^----------------------------------------------------------------------------------------
_u_: b-w-up |(a |(a*))  _b_: b-w  ) |(a) |(b)*  _f_: f-w  *(a)| (b)| (  _a_: b-w-down ((|a) b|)*
_e_: up     (a (b*)|)|  _p_: prev )| (a)| (b)*  _n_: next *(a) |(b) |(  _d_: down     *(|a (|b))
"
  ("b" paredit-backward)
  ("f" paredit-forward)
  ("p" paredit-previous)
  ("n" paredit-next)
  ("a" paredit-backward-down)
  ("d" paredit-forward-down)
  ("u" paredit-backward-up)
  ("e" paredit-forward-up))

(defhydra hydra-paredit-bracket (:hint nil)
  "\n_[_: <--(    _{_: (-->    _}_: <--)    _]_: )-->\n"

  ("[" paredit-backward-slurp-sexp)
  ("{" paredit-backward-barf-sexp)
  ("]" paredit-forward-slurp-sexp)
  ("}" paredit-forward-barf-sexp))

;; 仅显示 hydra,不执行实质操作
(dotemacs-leader/set-key
 "ss" 'hydra-paredit-cursor/body)

;; 以下快捷键除了执行绑定动作,同时会显示 hydra
(let ((maps
       (if (boundp 'evil-mode)
           (list evil-normal-state-map evil-insert-state-map)
         (list global-map)))
      (defs
        `(;; 光标快捷键(经典风格)
          (hydra-paredit-cursor/body  . ("C-M-a" . paredit-backward-down))
          (hydra-paredit-cursor/body  . ("C-M-b" . paredit-backward))
          (hydra-paredit-cursor/body  . ("C-M-d" . paredit-forward-down))
          (hydra-paredit-cursor/body  . ("C-M-e" . paredit-forward-up))
          (hydra-paredit-cursor/body  . ("C-M-f" . paredit-forward))
          (hydra-paredit-cursor/body  . ("C-M-n" . paredit-next))
          (hydra-paredit-cursor/body  . ("C-M-p" . paredit-previous))
          (hydra-paredit-cursor/body  . ("C-M-u" . paredit-backward-up))
          ;; 光标快捷键(leader key 形式)
          (hydra-paredit-cursor/body  . (,(concat dotemacs-leader/leader " s a") . paredit-backward-down))
          (hydra-paredit-cursor/body  . (,(concat dotemacs-leader/leader " s b") . paredit-backward))
          (hydra-paredit-cursor/body  . (,(concat dotemacs-leader/leader " s d") . paredit-forward-down))
          (hydra-paredit-cursor/body  . (,(concat dotemacs-leader/leader " s e") . paredit-forward-up))
          (hydra-paredit-cursor/body  . (,(concat dotemacs-leader/leader " s f") . paredit-forward))
          (hydra-paredit-cursor/body  . (,(concat dotemacs-leader/leader " s n") . paredit-next))
          (hydra-paredit-cursor/body  . (,(concat dotemacs-leader/leader " s p") . paredit-previous))
          (hydra-paredit-cursor/body  . (,(concat dotemacs-leader/leader " s u") . paredit-backward-up))
          ;; 括号快捷键
          (hydra-paredit-bracket/body . (,(concat dotemacs-leader/leader " s [") . paredit-backward-slurp-sexp))
          (hydra-paredit-bracket/body . (,(concat dotemacs-leader/leader " s {") . paredit-backward-barf-sexp))
          (hydra-paredit-bracket/body . (,(concat dotemacs-leader/leader " s ]") . paredit-forward-slurp-sexp))
          (hydra-paredit-bracket/body . (,(concat dotemacs-leader/leader " s }") . paredit-forward-barf-sexp))
          )))
  (mapcar (lambda(map)
            (mapcar (lambda (def)
                      (let ((hydra-body (car def))
                            (key-fn (cdr def)))
                        (define-key map (kbd (car key-fn))
                          `(lambda (&optional count)
                             (interactive "P")
                             (apply ',(cdr key-fn) count)
                             (when (not count)
                               (,hydra-body))))
                        ))
                    defs))
          maps)
  )

当中的 dotemacs-leader 是我自己写的一个乞丐版 evil-leader,替换掉应该没什么问题。


#28

非常感谢!zsbd