在大多数现代编辑器中,您可以突出显示一段代码并缩进或取消缩进一个制表符或您正在使用的许多空格,这是标准的;你如何在emacs中做到这一点?
因此,例如我刚刚打开了 sublime text,突出显示了以下代码:
variation1 person phoneMap carrierMap addressMap =
case M.lookup person phoneMap of
Nothing -> Nothing
Just number ->
case M.lookup number carrierMap of
Nothing -> Nothing
Just carrier -> M.lookup carrier addressMap
然后按下标签并得到
variation1 person phoneMap carrierMap addressMap =
case M.lookup person phoneMap of
Nothing -> Nothing
Just number ->
case M.lookup number carrierMap of
Nothing -> Nothing
Just carrier -> M.lookup carrier addressMap
该代码上的一个 shift-tab 将其返回到原来的位置,如果我继续按 shift-tab,我最终会得到以下信息:
variation1 person phoneMap carrierMap addressMap =
case M.lookup person phoneMap of
Nothing -> Nothing
Just number ->
case M.lookup number carrierMap of
Nothing -> Nothing
Just carrier -> M.lookup carrier addressMap
引用另一个回复:
emacs 语言模式实际上并没有“进一步缩进此块 1 选项卡”的概念。相反,他们非常固执己见,并且有“这是正确的缩进”的概念,这就是您在语言模式下点击制表符时所得到的。
除非我使用以下代码执行此操作(haskell 模式和 ghc mod 已启用):
import Monad
import System
import IO
import Random
import Control.Monad.State
type RandomState a = State StdGen a
data CountedRandom = CountedRandom {
crGen :: StdGen
, crCount :: Int
}
type CRState = State CountedRandom
getRandom :: Random a => RandomState a
getRandom =
get >>= \gen ->
let (val, gen') = random gen in
put gen' >>
return val
我得到以下信息:
import Monad
import System
import IO
import Random
import Control.Monad.State
type RandomState a = State StdGen a
data CountedRandom = CountedRandom {
crGen :: StdGen
, crCount :: Int
}
type CRState = State CountedRandom
getRandom :: Random a => RandomState a
getRandom =
get >>= \gen ->
let (val, gen') = random gen in
put gen' >>
return val
当我想要
import Monad
import System
import IO
import Random
import Control.Monad.State
type RandomState a = State StdGen a
data CountedRandom = CountedRandom {
crGen :: StdGen
, crCount :: Int
}
type CRState = State CountedRandom
getRandom :: Random a => RandomState a
getRandom =
get >>= \gen ->
let (val, gen') = random gen in
put gen' >>
return val
足够接近来自ataylor的解决方案:
(defcustom tab-shift-width 4
"Sets selected text shift width on tab"
:type 'integer)
(make-variable-buffer-local 'tab-shift-width)
(global-set-key
(kbd "<tab>")
(lambda (start end)
(interactive "r")
(if (use-region-p)
(save-excursion
(let ((deactivate-mark nil))
(indent-rigidly start end tab-shift-width)))
(indent-for-tab-command))))
(global-set-key
(kbd "S-<tab>")
(lambda (start end)
(interactive "r")
(if (use-region-p)
(save-excursion
(let ((deactivate-mark nil))
(indent-rigidly start end (- tab-shift-width))))
(indent-for-tab-command))))
如果 emacs 支持缩进检测(即,只获取某个变量的值),那就太好了;我发现与此最接近的是一个名为 dtrt indent 的插件,但它不适用于 Haskell。