emacs - 为什么 haskell 模式会使用 s-lower-camel-case,它是如何做到的?

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

有没有人有什么想法?

最佳答案

这是由于语法条目定义了“单词”是什么。在 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/

相关文章:

emacs - 从 Emacs 在 Docker 容器上运行命令

emacs - 任何可用于浏览数据库(查看模式、运行 sql 查询)的 emacs 包?

debugging - 如何调试字体锁定关键字错误

emacs - 如何将 elisp 列表放入 elisp 哈希

emacs - emacs 中的 "open buffer here"(ido 模式)

javascript - 在 Emacs 中使用 js2 模式正确缩进缓冲区

c++ - 在 Windows 7 中的 Emacs 上编译和运行 C++

emacs - Emacs 中 sexp 和 list 的区别?

emacs - 使用区域缩进函数保持区域标记

emacs,取消分割特定的窗口分割