spacemacs Python Layer的snippet

java还是ide或者vs code走起吧。。。目前没啥完美的解决方案

这个确实是,ideavim visual selection还跟某些功能冲突,比方说extend region使用的还是原来的选择模式,而不是ideavim的,就无法删除。

嘿嘿我把他改为全局Key了顺便加了个在结尾加了个(newline),多谢多谢! 第一天入坑的我还是挺高兴的。

改进版,判断行尾字符决定是 insert 还是 remove,支持多行:

(defun insert-or-remove-trailing-char (&optional ch)
  (interactive)
  (let ((ch (or ch (read-char "Input char: ")))
        (fn (lambda (ch)
              (end-of-line)
              (if (eq (char-before) ch)
                  (delete-backward-char 1)
                (insert-char ch)))))
    (save-excursion
      (if (region-active-p)
          (save-restriction
            (narrow-to-region (region-beginning) (region-end))
            (deactivate-mark)
            (goto-char (point-min))
            (funcall fn ch)
            (while (< (point) (- (point-max) 1))
              (next-line)
              (funcall fn ch)))
        (funcall fn ch)))))

(defun insert-or-remove-trailing-semi ()
  (interactive)
  (insert-or-remove-trailing-char ?\;))

(defun insert-or-remove-trailing-comma ()
  (interactive)
  (insert-or-remove-trailing-char ?,))
1 个赞

再分享一个:

(defun ins-c++-curly ()
  "Insert {}.
Threat is as function body when from endline before )"
  (interactive)
  (if (looking-back "\\()\\|try\\|else\\|const\\|:\\)$")
      (progn
        (insert " {\n\n}")
        (indent-according-to-mode)
        (forward-line -1)
        (indent-according-to-mode))
    (insert "{}")
    (backward-char)))

(add-hook 'c-mode-common-hook 'my-c-common-hook)

(defun my-c-common-hook ()
  (define-key c-mode-base-map "{" 'ins-c++-curly))

这是我刚入坑的时候急切寻找的另一个function,输入大括号并换行并把光标放在中间(我绑了个<C-return>然后把if去掉了)。来源在这里:cc mode - New line and autoindent braces in ccmode in Emacs - Stack Overflow


题外话:

逗号的话,因为在行尾输入之后没有要跑回前面括号里这样的问题,我竟然一直没想到它可以和分号一样简化一下 :joy: 这次抛砖引玉我给自己打9.9分

编辑 json 或数组之类的数据就要用到逗号了。