/
init-navigate.el
101 lines (89 loc) · 3.06 KB
/
init-navigate.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
;;; -*- lexical-binding: t -*-
;; 改变光标移动绑定,使其更加方便
(global-set-key (kbd "C-f") '+smart-forward)
(defun +smart-forward ()
"Move cursor based on its position in a word."
(interactive)
(cond
((looking-at "\\w") (forward-word 1))
((looking-at "\\s-") (progn (re-search-forward "\\S-") (backward-char)))
(t (forward-char))))
;; (global-set-key (kbd "C-b") 'backward-word)
;; (defun +smart-backword ()
;; "Move cursor based on its position in a word."
;; (interactive)
;; (cond
;; ((looking-at "\\w") (backward-word)) ; 如果在单词中部,移动到单词头部
;; ((looking-back "\\b" 1) (backward-word) (forward-word)) ; 如果在单词头部,移动到前一个单词的尾部
;; ((looking-at "\\s-") (backward-word))
;; (t (backward-char)))) ; 如果不在单词中,显示消息
;; (global-set-key (kbd "C-l") 'forward-char)
;; (global-set-key (kbd "C-h") 'backward-char)
;; 字符跳转
(use-package avy
:straight t
:bind
("C-h" . avy-goto-char-2)
:config
(setq avy-timeout-seconds 0.3) ; 0.3 秒后如果不连续击键,那么进入选择阶段
(setq avy-background t) ; 在跳转时背景变黑
:init
(setq avy-single-candidate-jump nil)
;; (advice-add 'avy-action-goto :after (lambda (&rest _args)
;; (forward-word)))
)
(use-package ace-pinyin
:straight t
:after avy
:init (ace-pinyin-global-mode t))
;; 增强 C-e 使得其可以在关键位置进行循环移动
(use-package mwim
:straight t
:bind (([remap move-beginning-of-line] . mwim-beginning-of-code-or-line)
([remap move-end-of-line] . mwim-end-of-code-or-line)))
;; [beginend] Better M-< M-> for programming
(use-package beginend
:straight t
:hook (after-init . beginend-global-mode))
;; 结构化跳转
(use-package imenu
:straight nil
:hook ((prog-mode conf-mode yaml-mode markdown-mode org-mode) . imenu-add-menubar-index)
:config
(setq imenu-auto-rescan t)
)
;; 中文分词跳转
(use-package cns
:init
(add-to-list 'load-path (expand-file-name "site-lisp/emacs-chinese-word-segmentation/" user-emacs-directory))
:hook
(org-mode . cns-mode)
(gfm-mode . cns-mode)
(markdown-mode .cns-mode)
(eww-mode . cns-mode)
:bind
(:map cns-mode-map
("C-f" . +smart-forward-cn))
:init
(setq cns-prog (expand-file-name "site-lisp/emacs-chinese-word-segmentation/cnws" user-emacs-directory))
(setq cns-dict-directory (expand-file-name "site-lisp/emacs-chinese-word-segmentation/cppjieba/dict" user-emacs-directory))
:config
(defun +cns-forward-word ()
(interactive)
(if (org-at-table-p)
(+smart-forward)
(cns-forward-word)))
(defun +smart-forward-cn ()
"Move forward one word or to the end of line."
(interactive)
(let ((current-line (line-number-at-pos))
(current-point (point)))
(if (eolp)
(+cns-forward-word)
(progn
(+cns-forward-word)
(when (/= current-line (line-number-at-pos))
(progn
(goto-char current-point)
(end-of-line)))))))
)