emacs实用小功能

Posted by [Kohn] on Monday, May 8, 2023 本文阅读量

1 移动类

切换窗口

(windmove-default-keybindings)
(setq windmove-wrap-around t)

之后可以通过shift-方向键切换窗口

2 编辑类

将json拍平成一行

(defun json-to-single-line (beg end)
Collapse prettified json in region between BEG and END to a single line(interactiver”)
(if (use-region-p)
(save-excursion
(save-restriction
(narrow-to-region beg end)
(goto-char (point-min))
(while (re-search-forward\\s-+\\|\n” nil t)
(replace-match “”))))
(printThis function operates on a region”)))

json-mode内置的json-mode-beautify是将杂乱的json片段按照一定的缩进格式化一下, 例如:

{
    "Name": "hehe"
}

而上面这个函数是将json片段整理成独立的一行:

{"Name":"hehe"}

使用时选中要拍平的json段, 然后M-x json-to-single-line