【问题标题】:Turn off automatic lambda character in Emacs关闭 Emacs 中的自动 lambda 字符
【发布时间】:2014-01-07 12:26:14
【问题描述】:

我安装的 GNU Emacs 24.3.1 是“有用地”将单词“lambda”(在 python 模式中)和“fn”(在 clojure 模式中)转换为希腊符号 λ。我敢肯定这会让一些人高兴,但我不是其中之一。 :)

有没有 Emacs 黑客知道如何关闭这个不需要的功能?

我在init.el 中尝试了以下方法,但无济于事:

(defconst keywords-to-remove (lambda fn))
(font-lock-remove-keywords 'clojure-mode keywords-to-remove)
(font-lock-remove-keywords 'lisp-mode keywords-to-remove)
(font-lock-remove-keywords 'python-mode keywords-to-remove)

这是我init.el的当前内容:

(require 'package)
(add-to-list 'package-archives
             '("marmalade" . "http://marmalade-repo.org/packages/") t)

(package-initialize)

(when (not package-archive-contents)
  (package-refresh-contents))

(defvar my-packages '(starter-kit
                      starter-kit-lisp
                      starter-kit-bindings
                      auto-complete
                      slime
                      ac-slime
                      rainbow-delimiters
                      clojure-mode
                      nrepl))

(dolist (p my-packages)
  (when (not (package-installed-p p))
    (package-install p)))

(global-set-key (kbd "<C-tab>") 'next-multiframe-window)

(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
(ac-config-default)
(setq ac-delay 0.2) ;; eclipse uses 500ms

(add-to-list 'load-path "~/.emacs.d/ac-slime")
(require 'ac-slime)
(add-hook 'slime-mode-hook 'set-up-slime-ac)
(add-hook 'slime-repl-mode-hook 'set-up-slime-ac)

(setq default-truncate-lines t)

(defun indent-buffer ()
  "Indents an entire buffer using the default intenting scheme."
  (interactive)
  (save-excursion
    (delete-trailing-whitespace)
    (indent-region (point-min) (point-max) nil)
    (untabify (point-min) (point-max))))

(require 'rainbow-delimiters)
(global-rainbow-delimiters-mode)

(require 'color-theme)
(eval-after-load "color-theme"
  '(progn
     (color-theme-initialize)
     (color-theme-ld-dark)))

(add-to-list 'auto-mode-alist '("\\.cljs\\'" . clojure-mode))

;; Allow input to be sent to somewhere other than inferior-lisp
;;
;; This is a total hack: we're hardcoding the name of the shell buffer
(defun shell-send-input (input)
  "Send INPUT into the *shell* buffer and leave it visible."
  (save-selected-window
    (switch-to-buffer-other-window "*shell*")
    (goto-char (point-max))
    (insert input)
    (comint-send-input)))

(defun defun-at-point ()
  "Return the text of the defun at point."
  (apply #'buffer-substring-no-properties
         (region-for-defun-at-point)))

(defun region-for-defun-at-point ()
  "Return the start and end position of defun at point."
  (save-excursion
    (save-match-data
      (end-of-defun)
      (let ((end (point)))
        (beginning-of-defun)
        (list (point) end)))))

(defun expression-preceding-point ()
  "Return the expression preceding point as a string."
  (buffer-substring-no-properties
   (save-excursion (backward-sexp) (point))
   (point)))

(defun shell-eval-last-expression ()
  "Send the expression preceding point to the *shell* buffer."
  (interactive)
  (shell-send-input (expression-preceding-point)))

(defun shell-eval-defun ()
  "Send the current toplevel expression to the *shell* buffer."
  (interactive)
  (shell-send-input (defun-at-point)))

(add-hook 'clojure-mode-hook
          (lambda ()
             (define-key clojure-mode-map (kbd "C-c e") 'shell-eval-last-expression)
             (define-key clojure-mode-map (kbd "C-c x") 'shell-eval-defun)))

【问题讨论】:

  • 您应该检查font-lock-keywords 变量以查看这些字符串 (lambda, fn) 是否存在一些特殊规则。如果是这样,摆脱那些,你很高兴去。 Reference.
  • 谢谢,Noufal,这给了我一个开始寻找的地方。你为什么不回答而不是评论?
  • 这不是 Emacs 的默认行为,因此罪魁祸首很可能是您自己添加的库(或者可能是 default.elsite-start.el 中的某些内容,如果它们存在于默认加载中的任何位置-path,但现在这并不常见)。
  • 您可以通过运行emacs -q 来检查它是否在您的站点配置中。这不会加载您的init.el,但会加载site-start.el。因此,如果emacs -q 导致该行为,则它在site-start.el 中。这不太可能;它可能在您的init.el 中。

标签: emacs clojure


【解决方案1】:

如果您使用 starter-kit,那么您还可以通过以下方式关闭 esk-pretty-lambdas 功能:

(remove-hook 'prog-mode-hook 'esk-pretty-lambdas)

在您的 dot emacs 或 init 文件中。

【讨论】:

  • 很有魅力!我想这教会了我在询问 Emacs 问题时始终包含我的 init.el 内容;所以你已经回答和元回答了。 ;)
【解决方案2】:

Emacs-24.4 有一个新的全局次要模式prettify-symbols-mode 来控制它。我建议您联系您的主要模式的维护者,并要求他们在定义此次要模式时尝试并遵守它。

【讨论】:

  • 好的,但这对我没有帮助,因为我运行的是 24.3。
  • @JoshGlover,实际上,prettify-symbols-mode 至少也在 24.3.50.1 中,并且可能在此之前的几个版本中。尝试C-h m 以查看此模式是否处于活动状态。如果没有,请检查pretty-modepurty-mode,这两个类似的第三方库。
  • 谷歌搜索"λ" emacs clojure-mode lisp-mode python-mode点击pretty-mode.el
  • 递归地一分为二你的 init 文件,找出哪个代码负责美化lambda——有多种可能性(包括pretty-lambdada.el 和其他已经提到的)。根据罪魁祸首,根据该图书馆的文档所说的进行处理。
猜你喜欢
  • 2010-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多