我习惯在Ruby中使用regex,所以我是一个lisp noob。
(global-set-key (kbd "C-c t")
(lambda()
(interactive)
(if string-match-p file-name-directory "spec"
(shell-command (concat "rspec " (file-name-directory (buffer-file-name))))
)
)
)
基本上我想只在file-name-directory
中包含单词spec
的情况下运行此行(或“test”的其他内容)。
示例:/user/me/app/spec/test.rb
如何让if语句起作用?
到目前为止,我在迷你缓冲区中得到:Symbol's value as variable is void: string-match-p
。感谢。
答案 0 :(得分:1)
我假设您希望此操作在当前缓冲区上,如果是这样,请尝试以下操作:
(global-set-key (kbd "C-c t")
(lambda()
(interactive)
(let* ((full-name (buffer-file-name))
(path (when full-name
(file-name-directory full-name))))
(when (and path (string-match "spec" path))
(shell-command (concat "rspec " path))))))