emacs新手在ipython交互端卡死

;; 安装包的源
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://elpa.emacs-china.org/melpa/") t)
(add-to-list 'package-archives '("gnu" . "https://elpa.emacs-china.org/gnu/") t)
(add-to-list 'package-archives '("org" . "https://elpa.emacs-china.org/org/") t)
(package-initialize)

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages (quote (conda exec-path-from-shell youdao-dictionary))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

;; 配置conda虚拟环境
(require 'conda)
;; if you want interactive shell support, include:
(conda-env-initialize-interactive-shells)
;; if you want eshell support, include:
(conda-env-initialize-eshell)
;; if you want auto-activation (see below for details), include:
(conda-env-autoactivate-mode t)
;; 指定anaconda的安装目录
;;(custom-set-variables
;; '(conda-anaconda-home "~/anaconda3/"))
(setq conda-anaconda-home (expand-file-name "~/anaconda3"))
;; 指定anaconda的配置目录
(setq conda-env-home-directory (expand-file-name "~/anaconda3/"))
;; if you want interactive shell support, include:
(conda-env-initialize-interactive-shells)
;; if you want eshell support, include:
(conda-env-initialize-eshell)

;; 项目地址
;;(add-to-list 'python-shell-extra-pythonpaths "/home/yinxiuqu/projects/quantming")

;; python路径
(setq python-shell-interpreter "/home/yinxiuqu/anaconda3/envs/quantaxis/bin/python3.8")

;; 设置环境变量
(setenv "PATH" "/home/yinxiuqu/projects/quantming")
;; (setenv "HOME" "/home/yinxiuqu/projects/quantming")
;; (setq default-directory "/home/yinxiuqu/temp")
(setq command-line-default-directory "/home/yinxiuqu/temp")
;; (setq exec-path (append exec-path '("/home/yinxiuqu/projects/quantming" "/home/yinxiuqu/temp")))

;; 设置和系统互相粘贴
(setq x-select-enable-clipboard t)

;; 有道词典Enable Cache
(setq url-automatic-caching t)
(global-set-key (kbd "C-q") 'youdao-dictionary-search-at-point+)

;; 启用文本模式并自动换行
(setq default-major-mode 'text-mode)
(add-hook 'text-mode-hook 'turn-on-auto-fill)

;; 禁用\e\e和\C-x\C-u
(global-unset-key "\e\e")
(global-unset-key "\C-x\C-u")

;; 将python项目跟目录设置为root
(defvar my-python-shell-dir-setup-code 
  "import os
home = os.path.expanduser('~')
while os.path.isfile('__init__.py') and (os.getcwd() != home):
    os.chdir('..')
del os")

;; eshell自动启用conda虚拟环境
(defun my-python-shell-dir-setup ()
  (let ((process (get-buffer-process (current-buffer))))
    (python-shell-send-string my-python-shell-dir-setup-code process)
    (message "Setup project path")))
(add-hook 'inferior-python-mode-hook 'my-python-shell-dir-setup)

;; windows下防止emacs假死/卡死
;; (setq w32-get-true-file-attributes nil)

以上是我的.emacs.d/init.el文件的配置,我的系统是debian10 AMD64位,emacs是系统自带的26.1版。装了conda.el,使用了虚拟的python环境,eshell进入ipython交互界面后,输入的表达式过长,就会假死,几十秒钟才动一下,如下图:

主要是一个CPU会飙升到100%,复制粘贴长句的时候就会这样。

function update_gui_emacs()
 {
   # dep: libjansson-dev libgnutls28-dev texinfo libgif-dev libgtk-3-dev libjpeg-dev libxpm-dev
   git clone --depth=1
 https://gitee.com/mirrors/emacs.git ~/.myemacs
   cd ~/.myemacs
   ./autogen.sh
   ./configure --prefix=$HOME/.local
 --with-xft=ifavailable --with-mailutils=ifavailable
 -with-xpm=ifavailable --with-jpeg=ifavailable
 --with-gif=ifavailable --with-tiff=ifavailable
 --with-png=ifavailable  --with-json=ifavailable
 --with-gnutls=ifavailable
 --program-transform-name='s/^ctags$/ctags.emacs/'
 --enable-link-time-optimization  CFLAGS="-O3
 -march=native" --with-native-compilation=ifavailable

   make
   make install
   cd -
 }

编译一个新的吧,太老的版本想试着复现都很麻烦…

装了新版本,一切正常,但是Message里有一个警告 debian-ispell-set-startup-menu: Symbol’s value as variable is void: ispell-menu-map-needed,此外,还提示Eshell Conda environment support initialized. [2 times] 2times怎么回事?

谢谢老大,我刚才装了emacs27.1,复制长句仍然会卡死。我只能按您的方法编译emacs28.1试试了。

编译完之后,怎么知道是否编译成功?我似乎找不到emacs,终端输入emacs没有

会是eshell 本身有局限么?我对eshell 不熟练,平时用的较少。

  • 如果是直接启动一个ipython,一般我会直接用terminal下的ipython,和emacs 无关。或者我会在emacs 里面运行vterm,利用这个终端。
  • 如果是和脚本交互使用,来启动一个interactive python,我会参考spacemacs 里面调用repl的方式。这是我从spacemacs 里面抄写的,你可以看看这行怎么调用的。 其实,新手可以利用Purcell,spacemacs等现有的emacs 配置入门。
  • 你或许可以多利用在站内的搜索功能,看看之前在emacs使用eshell或者term 的经验?

我也估计是eshell自身的问题,我等会直接用系统的shell试试。谢谢

打开python文件后,我按C-c C-p C-c C-c运行了文件,然后在跳出的python ElDoc里面,粘贴了长句函数和参数,就卡死。不知道这个是不是eshell,应该是python.el调用的ipython感觉。

C-c C-p C-c C-c 是执行什么命令呢? 你可以利用C-h k 来查看某一个key 代表什么命令,然后看看相应的函数大概在做什么? 感觉不像是和eshell 有关。另外,python-Eldoc ? 这个不是用来辅助显示变量是什么东西的呢? 不是用来运行python语句的地方吧?

命令就是把python文件send到ipython接口去运行,就是ipython运行的的界面,这里不能输入太长的语句,否则卡死。解决这个问题,emacs运行python就好玩了。目前就是这里被卡住。

我怀疑是python.el的问题,这里是它调用了ipython的交互模式。

(defun spacemacs//python-setup-shell (&rest args)
  "Set up python shell"
  (if (executable-find "ipython")
      (progn
        (setq python-shell-interpreter "ipython")
        ;; ipython version >= 5
        (setq python-shell-interpreter-args "--simple-prompt -i"))
    (progn
      (setq python-shell-interpreter "python")
      (setq python-shell-interpreter-args "-i")
      )
    )
  )

这是spacemacs 里面设置python-shell-interpreter的方法,它特别设置了python-shell-interpreter-args 这个参数。你或许试试这种设置策略,然后启动python,如M-x run-python, 再试试? 我没有遇到过你的问题,虽然我在emacs 里面使用python 已经很久了。

非常感谢,我试试。谢谢分享您的配置