emacs 中的制表符和空格完全清晰吗?

发布于 2024-07-23 09:36:28 字数 681 浏览 3 评论 0原文

我的问题的标题是对 emacs 中的正常选项卡的引用。

基本上我想要的是全局设置制表符和缩进以进行工作 某种统一的方式。 我感觉 emacs 比 TextMate 好多了 或 BBEdit 但实际上他们处理缩进的方式既简单又很棒 为了我的目的。 在 emacs 中,如果你使用一些制表符/空格方案 与您使用的次要模式强制执行的方案不同 麻烦。

当我按 Enter 键时,我想移动到缩进的下一行 使用选项卡的正确位置。 如果我能鱼与熊掌兼得,我会的 如果文件的其余部分已组成,则喜欢使用空格缩进 那样。

我也尝试过这些:
在 emacs 中执行选项卡
强制 emacs 使用选项卡

感谢任何可以帮助我实现这一目标的人。

-麦克风

The title of my question is a reference to sane tabs in emacs.

Basically what I want is to globally set tabs and indention to work in
some uniform way. I feel like emacs is so much better than TextMate
or BBEdit but really the way they handle indention is simple and great
for my purposes. In emacs if you use some tab/space scheme that's
different than the scheme enforced by a minor mode you use you're in
trouble.

When I press enter I'd like to be moved to the next line indented to
the right place using tabs. If I can have my cake and eat it too I'd
like to be indented using spaces if the rest of the file is composed
that way.

I've tried these also:

doing tabs in emacs

force emacs to use tabs

Thanks to anyone who can help me achieve this.

-Mike

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

天冷不及心凉 2024-07-30 09:36:28

也许 (global-set-key (kbd "RET") 'newline-and-indent) 是您想要的?
(或者reindent-then-newline-and-indent(如果可用的话),或者您只需按Cj而不是Enter键。)

Perhaps (global-set-key (kbd "RET") 'newline-and-indent) is what you want?
(Or reindent-then-newline-and-indent if that's available, or you could just hit C-j instead of the Enter key.)

荭秂 2024-07-30 09:36:28

对于你的问题的这一部分:

如果我能鱼与熊掌兼得,我想用空格缩进,如果其余的
文件就是这样组成的。

这是你想要的吗?

(defun dtrt-indent ()
  (setq indent-tabs-mode  
        (save-excursion
          (goto-char (point-min))
          (search-forward "\t" nil t))))
(add-hook 'text-mode-hook #'dtrt-indent)
(add-hook 'c-mode-hook #'dtrt-indent)
; etc for all modes you care about

因此,如果缓冲区中的任何位置有制表符,请使用制表符缩进; 如果没有制表符,则使用空格缩进。

For this part of your question:

If I can have my cake and eat it too I'd like to be indented using spaces if the rest of
the file is composed that way.

does this do what you want?

(defun dtrt-indent ()
  (setq indent-tabs-mode  
        (save-excursion
          (goto-char (point-min))
          (search-forward "\t" nil t))))
(add-hook 'text-mode-hook #'dtrt-indent)
(add-hook 'c-mode-hook #'dtrt-indent)
; etc for all modes you care about

So if there's a tab anywhere in the buffer, indent using tabs; if there is no tab, indent using spaces.

深海夜未眠 2024-07-30 09:36:28

如果您按照描述进行设置:

(setq indent-tabs-mode t)
(setq-default indent-tabs-mode t)
(setq tab-width 4) ;; 8 is way too many
(setq default-tab-width 4) ;; 8 is way too many
(global-set-key (kbd "RET") 'newline-and-indent)

indent-tabs-mode 会告诉 emacs 通过使用 TABS 和 SPACES 来创建所需的缩进(由单独的模式定义)。 这意味着,如果您想插入 TAB 而不是 TABS/空格,则需要将模式配置为使用 tab-width 作为缩进。

例如,如果您使用 c-mode 并选择 cc-mode 作为缩进样式(使用 Cc . 选择),它使用 4 作为缩进值, newline-and-indent 将插入空格。

结论:

  1. 检查您的模式是否使用 tab-width 作为缩进
  2. 检查您的模式是否覆盖 indent-tabs-mode (python-mode 似乎是这样做的)

虽然我个人不喜欢 TABS 祝你旅途顺利:)

if you do your setup as described:

(setq indent-tabs-mode t)
(setq-default indent-tabs-mode t)
(setq tab-width 4) ;; 8 is way too many
(setq default-tab-width 4) ;; 8 is way too many
(global-set-key (kbd "RET") 'newline-and-indent)

The indent-tabs-mode thing will tell emacs to create your indentation by using TABS and SPACES to make up the desired indentation (defined by the individual mode). This means, if you want to have a TAB inserted instead of TABS/SPACES you need to configure your mode to use tab-width as indentation.

For example if you use c-mode and select cc-mode as indentation style (select with C-c .) which uses 4 as indentation value, newline-and-indent will insert spaces.

To conclude:

  1. Check that your mode uses tab-width as indentation
  2. Check that your mode doesn't overwride indent-tabs-mode (python-mode seems to do this)

Although I personally don't like TABS good luck on your journey :)

往日 2024-07-30 09:36:28

最好的策略是说服您选择的编程模式
按照您喜欢的方式缩进内容。 这通常很容易; 我是
对缩进很挑剔,我的 emacs 总是做正确的事情
自动地。 (这意味着“缩进区域”也总是
我想要什么,非常方便。)

The best strategy is to convince your programming mode of choice to
indent things the way you like. This is generally very easy; I am
picky about indentation and my emacs always does the right thing
automatically. (That means that "indent-region" also always does
what I want, which is very convenient.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文