diff --git a/.gitignore b/.gitignore index f526fb7..5f22c9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,5 @@ -# 忽略所有文件 * -# 保留特定配置文件 !init.el !early-init.el !custom.el @@ -9,5 +7,4 @@ !lisp/**/ !lisp/**/*.el -# 保留 .gitignore 本身 !.gitignore diff --git a/lisp/init-jinx.el b/lisp/init-jinx.el new file mode 100644 index 0000000..ab89107 --- /dev/null +++ b/lisp/init-jinx.el @@ -0,0 +1,80 @@ +;;; init-jinx.el --- Jinx configuration with consult-jinx -*- lexical-binding: t -*- + +;;; Commentary: +;; Jinx spell-checker configuration with consult-jinx menu + +;;; Code: + +(require 'jinx) +(require 'consult) + +(defvar consult-jinx--narrow + '((?m . "Misspelled")) + "Narrow keys for consult-jinx.") + +(defface consult-jinx-line-number-prefix + '((t :inherit line-number)) + "Face used for line numbers of misspellings from current line onwards.") + +(defface consult-jinx-line-number-wrapped + '((t :inherit consult-jinx-line-number-prefix :inherit warning :weight normal)) + "Face used for line numbers of misspellings before current line.") + +(defun consult-jinx--candidates () + "Return jinx misspellings as candidates list for consult." + (consult--forbid-minibuffer) + (unless jinx-mode + (user-error "Jinx mode not enabled in current buffer")) + (let* ((curr-line (line-number-at-pos (point))) + (overlays (jinx--force-overlays (point-min) (point-max))) + default-cand candidates) + (unless overlays + (user-error "No misspellings")) + (let* ((line-width (length (number-to-string (line-number-at-pos (point-max))))) + (word-width (apply #'max (mapcar + (lambda (ov) + (- (overlay-end ov) (overlay-start ov))) + overlays)))) + (dolist (ov overlays) + (let* ((start (overlay-start ov)) + (end (overlay-end ov)) + (line (line-number-at-pos start)) + (word (buffer-substring-no-properties start end)) + (line-str (propertize (format (format "%%%dd" line-width) line) + 'face (if (< line curr-line) + 'consult-jinx-line-number-wrapped + 'consult-jinx-line-number-prefix)))) + (push (propertize + (format (format "%%s %%-%ds" word-width) + line-str + (propertize word 'face 'error)) + 'consult--candidate (list (set-marker (make-marker) start) (cons 0 (- end start))) + 'consult--type ?m) + candidates) + (when (and (not default-cand) (>= line curr-line)) + (setq default-cand candidates))))) + (nreverse + (if default-cand + (let ((before (cdr default-cand))) + (setcdr default-cand nil) + (nconc before candidates)) + candidates)))) + +;;;###autoload +(defun consult-jinx () + "Jump to a jinx misspelled word." + (interactive) + (consult--read + (consult--with-increased-gc (consult-jinx--candidates)) + :prompt "Jinx misspelling: " + :category 'consult-jinx-misspelling + :history t + :require-match t + :sort nil + :narrow (consult--type-narrow consult-jinx--narrow) + :group (consult--type-group consult-jinx--narrow) + :lookup #'consult--lookup-candidate + :state (consult--jump-state))) + +(provide 'init-jinx) +;;; init-jinx.el ends here diff --git a/lisp/init-kbd.el b/lisp/init-kbd.el index c0f53ae..49378e6 100644 --- a/lisp/init-kbd.el +++ b/lisp/init-kbd.el @@ -8,8 +8,7 @@ ;; 使用F2打开init.el (defun open-init-file() - "Open user's init.el file in ~/.emacs.d -这是一段文档" + "Open user's init.el file in ~/.emacs.d" (interactive) (find-file "~/.emacs.d/init.el")) @@ -54,27 +53,30 @@ (global-set-key (kbd "M-l") 'downcase-dwim) ;; jinx相关 -(with-eval-after-load 'jinx - (defun my/jinx-smart-toggle () - "Toggle jinx-mode smartly. +(defun my/jinx-smart-toggle () + "Toggle jinx-mode smartly. Disable jinx-mode if it's enable and global-jinx-mode is disable , otherwise toggle global-jinx-mode." - (interactive) - (let ((local-on (bound-and-true-p jinx-mode)) - (global-on (bound-and-true-p global-jinx-mode))) - (cond - ((and local-on (not global-on)) - (message "disable jinx-mode in current buffer") - (jinx-mode -1)) - (t - (if global-on - (progn - (message "disable global-jinx-mode") - (global-jinx-mode -1)) + (interactive) + (unless (featurep 'jinx) + (require 'jinx)) + (let ((local-on (bound-and-true-p jinx-mode)) + (global-on (bound-and-true-p global-jinx-mode))) + (cond + ((and local-on (not global-on)) + (message "disable jinx-mode in current buffer") + (jinx-mode -1)) + (t + (if global-on (progn - (message "enable global-jinx-mode") - (global-jinx-mode 1)))))))) + (message "disable global-jinx-mode") + (global-jinx-mode -1)) + (progn + (message "enable global-jinx-mode") + (global-jinx-mode 1))))))) (global-set-key (kbd "C-c j j") 'my/jinx-smart-toggle) +(with-eval-after-load 'init-jinx + (global-set-key (kbd "C-c f j") 'consult-jinx)) ;; pair编辑 (global-set-key (kbd "C-c p d") 'delete-pair) @@ -146,7 +148,7 @@ Disable jinx-mode if it's enable and global-jinx-mode is disable , otherwise tog ;; 中键使用embark打开定义 (global-set-key (kbd "") 'xref-find-definitions) -;; 使用快速切换到scrath buffer +;; 使用快速切换到scratch buffer (if *is-mac* (global-set-key (kbd "C-C ") 'scratch-buffer) (global-set-key (kbd "C-c ") 'scratch-buffer)) @@ -194,6 +196,7 @@ Disable jinx-mode if it's enable and global-jinx-mode is disable , otherwise tog (global-set-key (kbd "C-c y") 'consult-yank-from-kill-ring) ;; 从kill ring中粘贴 (global-set-key (kbd "C-x r b") 'consult-bookmark) ;; 书签菜单,embark中有更多操作 (define-key minibuffer-local-map (kbd "C-c C-e") 'embark-export) ;; 把minibuffer结果在一个菜单中显示 +(global-set-key (kbd "C-c f e") 'consult-flycheck) ;; flycheck菜单 (if *is-mac* (progn (global-set-key (kbd "C-c f l") 'consult-fd-global) @@ -201,6 +204,12 @@ Disable jinx-mode if it's enable and global-jinx-mode is disable , otherwise tog (global-set-key (kbd "C-c f l") 'consult-locate) (global-set-key (kbd "C-c f m") 'consult-fd-global)) +;; flycheck +(global-set-key (kbd "C-c f c") 'global-flycheck-mode) +(with-eval-after-load 'flycheck + (define-key flycheck-mode-map (kbd "M-{") 'flycheck-previous-error) + (define-key flycheck-mode-map (kbd "M-}") 'flycheck-next-error)) + ;; avy (global-set-key (kbd "C-M-;") 'avy-goto-char) (global-set-key (kbd "C-M-'") 'ace-pinyin-jump-char) diff --git a/lisp/init-package.el b/lisp/init-package.el index d12981e..460aed2 100644 --- a/lisp/init-package.el +++ b/lisp/init-package.el @@ -130,15 +130,24 @@ :config (setq jinx-languages "en_US") (add-to-list 'jinx-exclude-regexps '(t "\\cc")) (with-eval-after-load 'jinx - (dolist (range '((#x4E00 . #x9FFF) - (#x3400 . #x4DBF) - (#x3000 . #x303F) - (#xFF00 . #xFFEF) - (#x20000 . #x2A6DF))) - (let ((start (car range)) - (end (cdr range))) - (dotimes (i (- end start)) - (modify-syntax-entry (+ start i) "_" jinx--syntax-table)))))) + (dolist (range '((#x4E00 . #x9FFF) + (#x3400 . #x4DBF) + (#x3000 . #x303F) + (#xFF00 . #xFFEF) + (#x20000 . #x2A6DF))) + (let ((start (car range)) + (end (cdr range))) + (dotimes (i (- end start)) + (modify-syntax-entry (+ start i) "_" jinx--syntax-table))))) + (require 'init-jinx)) + +;; flycheck +(use-package flycheck + :init + (add-hook 'after-init-hook #'global-flycheck-mode)) + +;; consult-flycheck +(use-package consult-flycheck) ;; 安装emms (use-package emms