CeleritasCelery / emacs-native-shell-complete

Completion in shell buffers using native mechanisms
GNU Lesser General Public License v3.0
98 stars 9 forks source link

Can't get the completion effect shown in the README.org. #17

Closed hongyi-zhao closed 2 years ago

hongyi-zhao commented 2 years ago

On Ubuntu 20.04.3 LTS, I'm using the self compiled git master Emacs, and try to install emacs-native-shell-complete with the following configuration following the guides here and here:

;; https://melpa.org/#/native-complete
;; https://melpa.org/#/company-native-complete
;; https://github.com/CeleritasCelery/emacs-native-shell-complete#1-emacs-setup
(use-package native-complete
  :straight ( :host github :repo "CeleritasCelery/emacs-native-shell-complete"
          :files (:defaults)
          ;; https://github.com/raxod502/straight.el#the-recipe-format
          ;; :includes indicates a package is a superset of another package.
          :includes company-native-complete
          )
  ;; https://github.com/CeleritasCelery/emacs-native-shell-complete#2-shell-setup
  :config
  (with-eval-after-load 'shell
    (native-complete-setup-bash))
  )

But I can't get the completion effect shown in the README.org when running M-x ansi-term RET in Emacs and then typing some commands, as shown in the screenshot below:

image

Any hints for this problem? See here for relevant discussions.

Regards, HZ

CeleritasCelery commented 2 years ago

Thanks for the issue. This package is only for shell-mode and doesn’t work in ansi-term-mode. See this for a description of the differences.

https://unix.stackexchange.com/questions/104325/what-is-the-difference-between-shell-eshell-and-term-in-emacs

hongyi-zhao commented 2 years ago

Thank you for your comment. I tried with M-x shell RET and still only see partial keywords complete, compare to what I see in the native shell console:

image

See the following keywords' candidate list, which is triggered in the native shell console:

$ echo $H<TAB>
$HISTCMD         $HISTFILESIZE    $HISTTIMEFORMAT  $HOSTNAME
$HISTFILE        $HISTSIZE        $HOME            $HOSTTYPE
kylesnowschwartz commented 2 years ago

Thank you for your comment. I tried with M-x shell RET and still only see partial keywords complete, compare to what I see in the native shell console:

I've just installed the package (thank you for finally making this!) and face a similar problem as the issue author.

~/Code/marketplace (main)$ echo $H
$HISTCMD       $HISTCONTROL   $HISTFILE      $HISTFILESIZE  $HISTSIZE      $HOME          $HOSTNAME      $HOSTTYPE

But in my emacs shell with native-complete echo $H<TAB> actually auto-completes to $HOME every time without displaying any of the options.

output from describe-mode

Enabled minor modes: Anzu Auto-Composition Auto-Compression
Auto-Encryption Clean-Aindent Column-Number Counsel Editorconfig
Electric-Indent Eval-Sexp-Fu-Flash Evil Evil-Escape Evil-Local
Evil-Surround Eyebrowse File-Name-Shadow Flycheck-Pos-Tip Font-Lock
Global-Anzu Global-Auto-Revert Global-Display-Line-Numbers Global-Eldoc
Global-Evil-Surround Global-Flycheck Global-Font-Lock Global-Git-Commit
Global-Git-Gutter+ Global-Hl-Line Global-Hl-Todo Global-Page-Break-Lines
Global-Rbenv Global-Spacemacs-Leader-Override Global-Undo-Tree
Global-Vi-Tilde-Fringe Ido-Vertical Ivy Line-Number Menu-Bar Mouse-Wheel
Override-Global Persp Projectile Projectile-Rails-Global Pupo Purpose
Recentf Save-Place Savehist Shell-Dirtrack Show-Smartparens
Show-Smartparens-Global Smartparens Spaceline-Info
Spacemacs-Leader-Override Transient-Mark Treemacs-Filewatch
Treemacs-Follow Treemacs-Fringe-Indicator Treemacs-Icons-Dired Undo-Tree
Vi-Tilde-Fringe Which-Key Winner Winum Xterm-Mouse Yas-Global
CeleritasCelery commented 2 years ago

Okay let's see if we can get to the bottom of this. First can you verify that we should be seeing more variables? Run env | grep '^H' in your shell buffer and look at the output.

Then can you run (native-complete-get-completion-style) when the cursor is at an empty shell prompt and see what it reports?

hongyi-zhao commented 2 years ago

Run env | grep '^H' in your shell buffer and look at the output.

$ env | grep '^H'
HISTTIMEFORMAT=%y-%m-%d %T 
HOME=/home/werner

Then can you run (native-complete-get-completion-style) when the cursor is at an empty shell prompt and see what it reports?

M-: (native-complete-get-completion-style) RET

image

CeleritasCelery commented 2 years ago

hmm. So it looks like several of those variables are bash specific and don't show up in the environment, but they should show up in completions.

image

I see in your company pop-up that it is using capf. Have you added company-native-complete to company-backends?

hongyi-zhao commented 2 years ago

M-x shell RET then M-: (add-to-list 'company-backends 'company-native-complete) RET will do the trick.

image

But as you can see, the prompt string will always display twice. And furthermore, the following error will often be triggered:

image

CeleritasCelery commented 2 years ago

I did a poor job documenting this requirement. Can you look at this newly added section of the readme and see if it explains it well? customize the prompt

Also I added a new function called native-complete-check-config that will check for common problems. Please run that as well.

hongyi-zhao commented 2 years ago

customize the prompt

I changed to the following configuration:

;; https://melpa.org/#/native-complete
;; https://melpa.org/#/company-native-complete
;; https://github.com/CeleritasCelery/emacs-native-shell-complete#1-emacs-setup
(use-package native-complete
  :straight ( :host github :repo "CeleritasCelery/emacs-native-shell-complete"
          :files (:defaults)
          ;; https://github.com/raxod502/straight.el#the-recipe-format
          ;; :includes indicates a package is a superset of another package.
          :includes company-native-complete
          )
  ;; https://github.com/CeleritasCelery/emacs-native-shell-complete#2-shell-setup
  :config
  ;; https://github.com/CeleritasCelery/emacs-native-shell-complete#if-using-company-mode
  (add-to-list 'company-backends 'company-native-complete)
  ;; https://github.com/CeleritasCelery/emacs-native-shell-complete#customize-the-prompt-regex
  (add-hook 'shell-mode-hook (lambda () (setq comint-prompt-regex "^.+[$%>] ")))
  ;; https://github.com/CeleritasCelery/emacs-native-shell-complete#bash
  (with-eval-after-load 'shell
    (native-complete-setup-bash))
  )

When I hit M-x shell RET, the following screenshot still will be triggered:

image

Also I added a new function called native-complete-check-config

I don't know how to use it. Any more hints?

CeleritasCelery commented 2 years ago

I don't know how to use it. Any more hints?

call it with M-x native-complete-check-config

hongyi-zhao commented 2 years ago

This following error is triggered by the aforementioned command:

image

CeleritasCelery commented 2 years ago

Thanks. I pushed a fix that will report the error message correctly. In this case just hit enter so that there is only one prompt on the line and it should work.

hongyi-zhao commented 2 years ago

Still encounter the same problem while issue M-x shell RET command:

$ git log -1
commit 5f94022fc9168971c77f8c12f9efd569c45f4850 (HEAD -> master, origin/master, origin/HEAD)
Author: Troy Hinckley <t.macman@gmail.com>
Date:   Mon Jan 24 11:06:15 2022 -0700

    Clarify error message in check config

image

CeleritasCelery commented 2 years ago

What error did it report?

hongyi-zhao commented 2 years ago

image

CeleritasCelery commented 2 years ago

That is a use-package error. Probably because you are not loading company mode before trying to assign company-backends

hongyi-zhao commented 2 years ago

Now, I added the :after company to native-complete's use-package configuration:

;; https://melpa.org/#/native-complete
;; https://melpa.org/#/company-native-complete
;; https://github.com/CeleritasCelery/emacs-native-shell-complete#1-emacs-setup
(use-package native-complete
  :straight ( :host github :repo "CeleritasCelery/emacs-native-shell-complete"
          :files (:defaults)
          ;; https://github.com/raxod502/straight.el#the-recipe-format
          ;; :includes indicates a package is a superset of another package.
          :includes company-native-complete
          )
  ;; https://github.com/CeleritasCelery/emacs-native-shell-complete/issues/17#issuecomment-1019382934
  ;; https://github.com/CeleritasCelery/emacs-native-shell-complete#2-shell-setup
  :after company
  :config
  ;; https://github.com/CeleritasCelery/emacs-native-shell-complete#if-using-company-mode
  (add-to-list 'company-backends 'company-native-complete)
  ;; https://github.com/CeleritasCelery/emacs-native-shell-complete#customize-the-prompt-regex
  (add-hook 'shell-mode-hook (lambda () (setq comint-prompt-regex "^.+[$%>] ")))
  ;; https://github.com/CeleritasCelery/emacs-native-shell-complete#bash
  (with-eval-after-load 'shell
    (native-complete-setup-bash))
  )

This fixed the warning mentioned above, but still the double prompt strings will be triggered:

image

CeleritasCelery commented 2 years ago

I don’t think that is related to this package. Do you still see the double prompt when you don’t use this package?

hongyi-zhao commented 2 years ago

You're right. This problem is triggered by comint-mime. See here for the related discussion.