>From d064827cf11e093c0c9a39052e0e04696b15c01d Mon Sep 17 00:00:00 2001 From: Ikumi Keita Date: Fri, 22 Oct 2021 22:28:37 +0900 Subject: [PATCH] Improve keymap handling * latex.el (LaTeX-mode-map): (LaTeX-common-initialization): * tex.el (VirTeX-common-initialization): (TeX-mode-map): Bind narrowing command just once. * latex.el (LaTeX-mode-map,LaTeX-common-initialization): Use `beginning-of-defun-function' and `end-of-defun-function' instead of overriding bindings of C-M-a and C-M-e. * preview.el.in (preview-mode-setup): (LaTeX-preview-setup): Bind preview tool button just once. --- latex.el | 13 +++++++++---- preview.el.in | 16 ++++++++-------- tex.el | 4 ++-- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/latex.el b/latex.el index c332ebf4..49c46786 100644 --- a/latex.el +++ b/latex.el @@ -5998,8 +5998,10 @@ environments." ;; (define-key map "\eq" 'LaTeX-fill-paragraph) ;*** Alias ;; This key is now used by Emacs for face settings. ;; (define-key map "\eg" 'LaTeX-fill-region) ;*** Alias - (define-key map "\e\C-e" #'LaTeX-find-matching-end) - (define-key map "\e\C-a" #'LaTeX-find-matching-begin) + ;; We now set `beginning-of-defun-function' and + ;; `end-of-defun-function' instead. + ;; (define-key map "\e\C-e" #'LaTeX-find-matching-end) + ;; (define-key map "\e\C-a" #'LaTeX-find-matching-begin) (define-key map "\C-c\C-q\C-p" #'LaTeX-fill-paragraph) (define-key map "\C-c\C-q\C-r" #'LaTeX-fill-region) @@ -6025,6 +6027,8 @@ environments." (define-key map "(" #'LaTeX-insert-left-brace) (define-key map "{" #'LaTeX-insert-left-brace) (define-key map "[" #'LaTeX-insert-left-brace) + + (define-key map "\C-xne" #'LaTeX-narrow-to-environment) map) "Keymap used in `LaTeX-mode'.") @@ -7045,6 +7049,9 @@ function would return non-nil and `(match-string 1)' would return (set (make-local-variable 'TeX-search-files-type-alist) LaTeX-search-files-type-alist) + (setq-local beginning-of-defun-function #'LaTeX-find-matching-begin + end-of-defun-function #'LaTeX-find-matching-end) + (set (make-local-variable 'LaTeX-item-list) '(("description" . LaTeX-item-argument) ("thebibliography" . LaTeX-item-bib) ("array" . LaTeX-item-array) @@ -7652,8 +7659,6 @@ function would return non-nil and `(match-string 1)' would return (use-local-map LaTeX-mode-map) - (define-key LaTeX-mode-map "\C-xne" #'LaTeX-narrow-to-environment) - ;; Initialization of `add-log-current-defun-function': (set (make-local-variable 'add-log-current-defun-function) #'TeX-current-defun-name) diff --git a/preview.el.in b/preview.el.in index 9dda6582..70c97988 100644 --- a/preview.el.in +++ b/preview.el.in @@ -3062,14 +3062,6 @@ pp") #'desktop-buffer-preview-misc-data) (add-hook 'pre-command-hook #'preview-mark-point nil t) (add-hook 'post-command-hook #'preview-move-point nil t) - (unless preview-tb-icon - (setq preview-tb-icon (preview-filter-specs preview-tb-icon-specs))) - (when preview-tb-icon - (define-key LaTeX-mode-map [tool-bar preview] - `(menu-item "Preview at point" preview-at-point - :image ,preview-tb-icon - :help "Preview on/off at point" - :vert-only t))) (when buffer-file-name (let* ((filename (expand-file-name buffer-file-name)) format-cons) @@ -3127,6 +3119,14 @@ to add the preview functionality." ["Report Bug" preview-report-bug])) (if (eq major-mode 'latex-mode) (preview-mode-setup)) + (unless preview-tb-icon + (setq preview-tb-icon (preview-filter-specs preview-tb-icon-specs))) + (when preview-tb-icon + (define-key LaTeX-mode-map [tool-bar preview] + `(menu-item "Preview at point" preview-at-point + :image ,preview-tb-icon + :help "Preview on/off at point" + :vert-only t))) (if (boundp 'desktop-buffer-misc) (preview-buffer-restore desktop-buffer-misc)))) diff --git a/tex.el b/tex.el index e3f4d118..eeca1aec 100644 --- a/tex.el +++ b/tex.el @@ -3809,8 +3809,6 @@ The algorithm is as follows: ;; we enter TeX mode the first time. (add-hook 'write-contents-functions #'TeX-safe-auto-write nil t) - (define-key TeX-mode-map "\C-xng" #'TeX-narrow-to-group) - ;; Minor modes (when TeX-source-correlate-mode (TeX-source-correlate-mode 1)) @@ -5024,6 +5022,8 @@ Brace insertion is only done if point is in a math construct and ;; Multifile (define-key map "\C-c_" #'TeX-master-file-ask) ;*** temporary + + (define-key map "\C-xng" #'TeX-narrow-to-group) map) "Keymap for common TeX and LaTeX commands.") -- 2.34.1