我已经准备了一个最小的工作示例来检查其他依赖项是否干扰了这个。测试函数为:
(defun test-haskell-problems ()
(interactive)
(insert (s-lower-camel-case "other_string")))
问题的完整重现(通过安装包)发生在这个:
(setq package-list '(
s
haskell-mode
))
(when (>= emacs-major-version 24)
(require 'package)
(package-initialize)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
)
; activate all the packages (in particular autoloads)
(package-initialize)
; fetch the list of packages available
(when (not package-archive-contents)
(package-refresh-contents))
; install the missing packages
(dolist (package package-list)
(when (not (package-installed-p package))
(package-install package)))
(require 's)
(defun test-haskell-problems ()
(interactive)
(insert (s-lower-camel-case "other_string")))
通过在 haskell 缓冲区中激活此函数 test-haskell-problems
我们得到字符串结果 other_string
预期结果并导致 *scratch*
缓冲区是 otherString
我不明白这里发生了什么?
有没有人有什么想法?
最佳答案
这是由于语法条目定义了“单词”是什么。在 Haskell 中,asdf_asdf 是一个单词,而 s.el 通过按单词拆分字符串来进行驼峰式拼写。
一个简单的解决方案是在临时缓冲区中执行 Camel 套管。
(insert (with-temp-buffer (s-lower-camel-case "asdf_asdf")))
更正确的解决方案是临时重新定义单词边界。
编辑:在这里
(insert (with-syntax-table (make-syntax-table) (s-lower-camel-case "asdf_asdf")))
这也快得多:
(benchmark 10000 '(with-temp-buffer (s-lower-camel-case "asdf_asdf")))
"Elapsed time: 1.188508s (0.204679s in 2 GCs)"
(benchmark 10000 '(with-syntax-table (make-syntax-table) (s-lower-camel-case "asdf_asdf")))
"Elapsed time: 0.368366s (0.191607s in 2 GCs)"
关于emacs - 为什么 haskell 模式会使用 s-lower-camel-case,它是如何做到的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25189322/