(setq package-archives '(("gnu" . "https://mirrors.ustc.edu.cn/elpa/gnu/") ("melpa" . "https://mirrors.ustc.edu.cn/elpa/melpa/") ("nongnu" . "https://mirrors.ustc.edu.cn/elpa/nongnu/"))) (use-package counsel :ensure t) (use-package ivy :ensure t :init (ivy-mode 1) (counsel-mode 1) :config (setq ivy-use-virtual-buffers t) (setq search-default-mode #'char-fold-to-regexp) (setq ivy-count-format "(%d/%d) ") :bind (("C-s" . 'swiper) ("C-x b" . 'ivy-switch-buffer) ("C-c v" . 'ivy-push-view) ("C-c s" . 'ivy-switch-view) ("C-c V" . 'ivy-pop-view) ("C-x C-@" . 'counsel-mark-ring); 在某些终端上 C-x C-SPC 会被映射为 C-x C-@,比如在 macOS 上,所以要手动设置 ("C-x C-SPC" . 'counsel-mark-ring) :map minibuffer-local-map ("C-r" . counsel-minibuffer-history))) (use-package ace-window :ensure t :bind (("C-x o" . 'ace-window))) (use-package undo-tree :ensure t :init (global-undo-tree-mode) :custom (undo-tree-auto-save-history nil)) (use-package which-key :ensure t :init (which-key-mode)) (use-package marginalia :ensure t :init (marginalia-mode) :bind (:map minibuffer-local-map ("M-A" . marginalia-cycle))) (use-package multiple-cursors :bind ("C-S-" . mc/toggle-cursor-on-click)) (use-package dashboard :ensure t :config (setq dashboard-banner-logo-title "Welcome to Emacs!") ;; 个性签名,随读者喜好设置 ;; (setq dashboard-projects-backend 'projectile) ;; 读者可以暂时注释掉这一行,等安装了 projectile 后再使用 (setq dashboard-startup-banner 'official) ;; 也可以自定义图片 (setq dashboard-items '((recents . 5) ;; 显示多少个最近文件 (bookmarks . 5) ;; 显示多少个最近书签 (projects . 10))) ;; 显示多少个最近项目 (dashboard-setup-startup-hook)) (use-package highlight-symbol :ensure t :init (highlight-symbol-mode) :bind ("" . highlight-symbol)) (use-package rainbow-delimiters :ensure t :hook (prog-mode . rainbow-delimiters-mode)) (use-package company :ensure t :init (global-company-mode) :config (setq company-minimum-prefix-length 1) ; 只需敲 1 个字母就开始进行自动补全 (setq company-tooltip-align-annotations t) (setq company-idle-delay 0.0) (setq company-show-numbers t) ;; 给选项编号 (按快捷键 M-1、M-2 等等来进行选择). (setq company-selection-wrap-around t) (setq company-transformers '(company-sort-by-occurrence))) ; 根据选择的频率进行排序,读者如果不喜欢可以去掉 (use-package yasnippet :ensure t :hook (prog-mode . yas-minor-mode) :config (yas-reload-all) ;; add company-yasnippet to company-backends (defun company-mode/backend-with-yas (backend) (if (and (listp backend) (member 'company-yasnippet backend)) backend (append (if (consp backend) backend (list backend)) '(:with company-yasnippet)))) (setq company-backends (mapcar #'company-mode/backend-with-yas company-backends)) ;; unbind completion (define-key yas-minor-mode-map [(tab)] nil) (define-key yas-minor-mode-map (kbd "TAB") nil) (define-key yas-minor-mode-map (kbd "") nil) :bind (:map yas-minor-mode-map ("S-" . yas-expand))) (use-package yasnippet-snippets :ensure t :after yasnippet) (use-package flycheck :ensure t :config (setq truncate-lines nil) ; 如果单行信息很长会自动换行 :hook (prog-mode . flycheck-mode)) (use-package lsp-mode :ensure t :init ;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l") (setq lsp-keymap-prefix "C-c l" lsp-file-watch-threshold 500) :hook (lsp-mode . lsp-enable-which-key-integration) ; which-key integration :commands (lsp lsp-deferred) :config (setq lsp-completion-provider :none) ;; 阻止 lsp 重新设置 company-backend 而覆盖我们 yasnippet 的设置 (setq lsp-headerline-breadcrumb-enable t) :bind ("C-c l s" . lsp-ivy-workspace-symbol)) ;; 可快速搜索工作区内的符号(类名、函数名、变量名等) (use-package lsp-ui :ensure t :config (define-key lsp-ui-mode-map [remap xref-find-definitions] #'lsp-ui-peek-find-definitions) (define-key lsp-ui-mode-map [remap xref-find-references] #'lsp-ui-peek-find-references) (setq lsp-ui-doc-position 'top)) (use-package lsp-ivy :ensure t :after (lsp-mode)) (use-package lsp-ivy :ensure t :after (lsp-mode)) (use-package magit :ensure t) (use-package c++-mode :functions ; suppress warnings c-toggle-hungry-state :hook (c-mode . lsp-deferred) (c++-mode . lsp-deferred) (c++-mode . c-toggle-hungry-state)) (use-package treemacs :ensure t :defer t :config (treemacs-tag-follow-mode) :bind (:map global-map ("M-0" . treemacs-select-window) ("C-x t 1" . treemacs-delete-other-windows) ("C-x t t" . treemacs) ("C-x t B" . treemacs-bookmark) ;; ("C-x t C-t" . treemacs-find-file) ("C-x t M-t" . treemacs-find-tag)) (:map treemacs-mode-map ("/" . treemacs-advanced-helpful-hydra))) (use-package treemacs-projectile :ensure t :after (treemacs projectile)) (use-package lsp-treemacs :ensure t :after (treemacs lsp)) (provide 'packages)