branch: externals/company
commit 5ce1cbaf7f111d8e7356ba968fe1cb03860b18ea
Merge: 32488c25fb 50a4c55a98
Author: Dmitry Gutov <[email protected]>
Commit: GitHub <[email protected]>

    Merge pull request #1537 from company-mode/better-doc-and-location-bindings
    
    Better default bindings for `company-show-doc-buffer` and 
`company-show-location`
---
 NEWS.md               | 15 +++++++++++++++
 company-childframe.el |  4 +++-
 company.el            | 41 ++++++++++++++++++++++++-----------------
 3 files changed, 42 insertions(+), 18 deletions(-)

diff --git a/NEWS.md b/NEWS.md
index f9287f4a6b..9adecdb63e 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,21 @@
 
 # Next
 
+* Default key bindings have been changed, moving `company-show-doc-buffer` and
+  `company-show-location` to `M-h` and `M-g` (from `C-h`/`<f1>` and `C-w`)
+  ([#1537](https://github.com/company-mode/company-mode/issues/1537)). The
+  previous bindings still work, but show a warning and will be removed after
+  the next release. To undo that change locally, do:
+
+```el
+(with-eval-after-load 'company
+  (define-key company-active-map (kbd "C-h") #'company-show-doc-buffer)
+  (define-key company-active-map (kbd "<f1>") #'company-show-doc-buffer)
+  (define-key company-active-map (kbd "C-w") #'company-show-location)
+  (define-key company-active-map (kbd "M-h") nil)
+  (define-key company-active-map (kbd "M-g") nil))
+```
+
 * `company-search-regexp-function` defaults to
   `company-search-words-in-any-order-regexp`. Another alternative value for it
   was also added: `company-search-flex-words-in-any-order-regexp`, working
diff --git a/company-childframe.el b/company-childframe.el
index d4bf2d2f5f..103948c52d 100644
--- a/company-childframe.el
+++ b/company-childframe.el
@@ -195,7 +195,9 @@ For COMMAND refer to `company-frontends'."
     (hide
      (company-childframe-hide))
     (post-command
-     (company-childframe-show))
+     (when (equal (window-buffer (selected-window))
+                  (current-buffer))
+       (company-childframe-show)))
     (select-mouse
      (company-childframe--select-mouse))))
 
diff --git a/company.el b/company.el
index 818e0fb411..83e116896f 100644
--- a/company.el
+++ b/company.el
@@ -897,8 +897,6 @@ asynchronous call into synchronous.")
   (let ((keymap (make-sparse-keymap)))
     (define-key keymap "\e\e\e" 'company-abort)
     (define-key keymap "\C-g" 'company-abort)
-    (define-key keymap (kbd "M-n") 'company--select-next-and-warn)
-    (define-key keymap (kbd "M-p") 'company--select-previous-and-warn)
     (define-key keymap (kbd "C-n") 'company-select-next-or-abort)
     (define-key keymap (kbd "C-p") 'company-select-previous-or-abort)
     (define-key keymap (kbd "<down>") 'company-select-next-or-abort)
@@ -917,9 +915,11 @@ asynchronous call into synchronous.")
     (define-key keymap (kbd "TAB") 'company-complete-common-or-cycle)
     (define-key keymap [backtab] 'company-cycle-backward)
     (define-key keymap (kbd "C-M-i") 'company-complete-common)
-    (define-key keymap (kbd "<f1>") 'company-show-doc-buffer)
-    (define-key keymap (kbd "C-h") 'company-show-doc-buffer)
-    (define-key keymap "\C-w" 'company-show-location)
+    (define-key keymap (kbd "<f1>") 'company--show-doc-buffer-and-warn)
+    (define-key keymap (kbd "C-h") 'company--show-doc-buffer-and-warn)
+    (define-key keymap (kbd "M-h") 'company-show-doc-buffer)
+    (define-key keymap (kbd "C-w") 'company--show-location-and-warn)
+    (define-key keymap (kbd "M-g") 'company-show-location)
     (define-key keymap "\C-s" 'company-search-candidates)
     (define-key keymap "\C-\M-s" 'company-filter-candidates)
     (company-keymap--bind-quick-access keymap)
@@ -928,22 +928,12 @@ asynchronous call into synchronous.")
 
 (defvar company--disabled-backends nil)
 
-(defun company--select-next-and-warn (&optional arg)
-  (interactive "p")
-  (company--warn-changed-binding)
-  (company-select-next arg))
-
-(defun company--select-previous-and-warn (&optional arg)
-  (interactive "p")
-  (company--warn-changed-binding)
-  (company-select-previous arg))
-
 (defun company--warn-changed-binding ()
   (interactive)
   (run-with-idle-timer
    0.01 nil
    (lambda ()
-     (message "Warning: default bindings are being changed to C-n and C-p"))))
+     (message "Warning: default bindings are being changed to M-h and M-g"))))
 
 (defun company-init-backend (backend)
   (and (symbolp backend)
@@ -2696,7 +2686,12 @@ For more details see `company-insertion-on-trigger' and
     (cancel-timer company-timer)
     (setq company-timer nil))
   (company-echo-cancel t)
-  (company-uninstall-map))
+  (unless (memq this-original-command
+                '(describe-key
+                  describe-key-briefly
+                  describe-map
+                  describe-bindings))
+    (company-uninstall-map)))
 
 (defun company-post-command ()
   (when (and company-candidates
@@ -3616,6 +3611,12 @@ automatically show the documentation buffer for each 
selection."
     (company--show-doc-buffer)))
 (put 'company-show-doc-buffer 'company-keep t)
 
+(defun company--show-doc-buffer-and-warn (&optional toggle-auto-update)
+  (interactive "P")
+  (company--warn-changed-binding)
+  (company-show-doc-buffer toggle-auto-update))
+(put 'company--show-doc-buffer-and-warn 'company-keep t)
+
 (defun company-show-location ()
   "Temporarily display a buffer showing the selected candidate in context."
   (interactive)
@@ -3637,6 +3638,12 @@ automatically show the documentation buffer for each 
selection."
           (set-window-start nil (point)))))))
 (put 'company-show-location 'company-keep t)
 
+(defun company--show-location-and-warn ()
+  (interactive)
+  (company--warn-changed-binding)
+  (company-show-location))
+(put 'company--show-location-and-warn 'company-keep t)
+
 ;;; package functions 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defvar-local company-callback nil)

Reply via email to