问题
I have prepared a minimal working example to check that other dependancies have not interfered with this. The test function is:
(defun test-haskell-problems ()
(interactive)
(insert (s-lower-camel-case "other_string")))
And a full reproduction of the problem (with package installation) occurs with this:
(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")))
By activating this function test-haskell-problems
in a haskell buffer we get the string result other_string
expected result and result in *scratch*
buffer is otherString
I don't understand what's happening here?
Does anyone have any ideas?
回答1:
This is due to the syntax entry that defines what a "word" is. In Haskell, asdf_asdf is one word and s.el does camelcasing by splitting a string by words.
An easy solution would be to perform your camel casing in a temporary buffer.
(insert (with-temp-buffer (s-lower-camel-case "asdf_asdf")))
A more correct solution would be to temporarily redefine the word boundaries.
EDIT: here it is
(insert (with-syntax-table (make-syntax-table) (s-lower-camel-case "asdf_asdf")))
This is also much faster:
(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)"
来源:https://stackoverflow.com/questions/25189322/why-does-haskell-mode-step-on-s-lower-camel-case-and-how-does-it-do-it