为什么haskell模式会在s-lower-camel-case上踩一下呢?它是如何做到的?

时间:2014-08-07 18:13:43

标签: emacs elisp

我准备了一个最小的工作示例来检查其他依赖项是否没有干扰这一点。测试功能是:

(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我不明白这里发生了什么?

有没有人有任何想法?

1 个答案:

答案 0 :(得分:3)

这是由于语法条目定义了" word"是。在Haskell中,asdf_asdf是一个单词,s.el通过按字符串分割字符串来实现。

一个简单的解决方案是在临时缓冲区中执行骆驼套管。

(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)"