emacs - 如何让 C-x C-e 只显示十进制和十六进制?

标签 emacs lisp elisp hex

这是 How to get C-x C-e to display the result in octal and hexadecimal by default? 的后续行动

有没有办法让 C-x C-e 只显示十进制和十六进制的结果?

例如

(+ 40 2)

应该产生

42 (#x2a)

代替

42 (#o52, #x2a, ?*)

最佳答案

您只需要重写/调整为此创建打印格式的例程。将以下内容添加到您的 .emacs 中,您就可以开始了。

(require 'simple)
(defun eval-expression-print-format (value)
  "Format VALUE as a result of evaluated expression.
Return a formatted string which is displayed in the echo area
in addition to the value printed by prin1 in functions which
display the result of expression evaluation."
  (if (and (integerp value)
           (or (not (memq this-command '(eval-last-sexp eval-print-last-sexp)))
               (eq this-command last-command)
               (if (boundp 'edebug-active) edebug-active)))
      (let ((char-string
             (if (or (if (boundp 'edebug-active) edebug-active)
                     (memq this-command '(eval-last-sexp eval-print-last-sexp)))
                 (prin1-char value))))
        (format " (#x%x)" value value))))

关于emacs - 如何让 C-x C-e 只显示十进制和十六进制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6752305/

相关文章:

具有默认值的 emacs 交互式命令

emacs - Emacs中如何实现代码折叠效果?

list - 如何在 Emacs Lisp 中设置列​​表中的部分参数?

emacs - AUCTex 问题中的预览

git - 如何配置 emacs.app 以在 *shell* 中使用 git for OSX 上的 git

sockets - 列表中的双向套接字

emacs - 如何在 Emacs Lisp 中以编程方式设置自定义变量?

lisp - 如何定义惰性 AND

lisp - 从另一个列表的原子在 LISP 中构建列表

macos - .emacs 识别操作系统的代码?