小编s.y*_*ari的帖子

Emacs Inferior Python shell使用每个python-shell-send-region命令显示发送消息

我在OS X(El Capitan)上使用Python劣质shell,每次我向Python进程发送一段代码(使用C-c C-r它都绑定python-shell-send-region)我在Python shell中得到这样的消息:

>>> import codecs, os;
    __pyfile = codecs.open('''/var/folders/6j/g9hcs1s17g1dgxr3p_m04rq80000gn/T/py5013kfY''', encoding='''utf-8''');
    __code = __pyfile.read().encode('''utf-8''');
    __pyfile.close();
    os.remove('''/var/folders/6j/g9hcs1s17g1dgxr3p_m04rq80000gn/T/py5013kfY''');
    exec(compile(__code, '''/Users/user/Desktop/sample.py''', 'exec'));
Run Code Online (Sandbox Code Playgroud)

我想在每次调用命令时都不会显示此消息.Linux上的相同版本的Emacs(以及python.el文件)没有此问题.消息的模板在python-shell-send-file函数中定义(在python.el文件中),这本身就令人费解,因为我无法看到在调用时如何调用此函数python-shell-send-region.对于第一次运行,我使用以下命令调用Python解释器(版本2.7.10)

/usr/bin/python -i
Run Code Online (Sandbox Code Playgroud)

但它也与其他python解释器(通过brew安装)的行为相同.我正在使用Emacs 24.5.1(再次通过brew安装).我使用的唯一特定于python模式的配置.emacs与选项卡宽度有关:

(add-hook 'python-mode-hook
      (lambda ()
        (setq indent-tabs-mode t)
        (setq tab-width 2)
        (setq python-indent 2)))
Run Code Online (Sandbox Code Playgroud)

任何帮助或建议表示赞赏.

编辑:

我在这个页面找到了一个解决方案(https://github.com/jorgenschaefer/elpy/issues/1307):

$ easy_install-3.6 gnureadline
$ cd /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload
$ mv readline.cpython-36m-darwin.so readline.cpython-36m-darwin.so.bak
Run Code Online (Sandbox Code Playgroud)

如果在安装gnureadline时出错fatal error: 'stdio.h' file not found,请尝试xcode-select --install.

python macos emacs python.el comint-mode

21
推荐指数
1
解决办法
1077
查看次数

根据另一个闭包来定义闭包

我有两个相互补充的闭包.我想用另一个来定义一个.例如,假设我们more-than定义了如下函数

(defun more-than (v) #'(lambda (x) (> x v)))

CL-USER> (funcall (more-than 5) 7)
T
CL-USER> (funcall (more-than 5) 3)
NIL
Run Code Online (Sandbox Code Playgroud)

我们想less-than-or-equal用上面的闭包来定义它的补充.这似乎并不像上面那样简单,因为我的尝试到目前为止还没有奏效.有人可以指出一个可能的解决方案,或者告诉我这是否是普通模式(即,不是独立于第一个闭包定义第二个闭包).

这是我的两个尝试不起作用

;; compile time error
(defun less-than-or-equal (v)
  #'(lambda (x) #'(not (more-than v))))
;; returns nil for every comparison
(defun less-than-or-equal (v)
  #'(lambda (x) (not (more-than v))))
Run Code Online (Sandbox Code Playgroud)

closures common-lisp

2
推荐指数
1
解决办法
73
查看次数

标签 统计

closures ×1

comint-mode ×1

common-lisp ×1

emacs ×1

macos ×1

python ×1

python.el ×1