我在运行带有最新补丁的Ubuntu 9.04的惠普笔记本上运行GNU Emacs 22.2.1。
最近,我需要处理一些PHP代码,所以我添加了Ubuntu的php模式包,认为我的.emacs中的内容将涵盖基础知识。好吧,差不多。以下简短代码段显示症状:
<?php
# main()
/*
*
*
*/
{
$fpath="/tmp";
// This is a comment
if (!file_exists($fpath)) {
// This is another comment
print "$fpath doesn't exist on the system!\n";
exit(1);
} elseif (!is_dir($fpath)) {
print "$fpath is not a directory\n";
exit(2);
} else
// I don't know why it doesn't use the } as the anchor position
// in PHP, but in C and C++?
print "Found $fpath on the system. Good...\n";
} # end of main()
请注意,两个注释和print语句都偏移了6个空格,而不是我想要的4个空格。我只有一个简单的.emacs,以及C / C ++的以下内容,我最广泛使用的两种语言:
[...]
(defconst my-c-style
'((c-comment-only-line-offset . 0)
(c-hanging-braces-alist . ((substatement-open after)
(brace-list-open)))
(c-hanging-colons-alist . ((member-init-intro before)
(inher-intro)
(case-label after)
(label after)
(access-label after)))
(c-cleanup-list . (scope-operator
empty-defun-braces
defun-close-semi))
(c-offsets-alist . ((arglist-close . c-lineup-arglist)
(substatement-open . 0)
(case-label . 4)
(block-open . 0)
(defun-block-intro . 0)
(statement-block-intro . 4)
(substatement . 4)
(knr-argdecl-intro . -)))
(c-echo-syntactic-information-p . t)
)
"My C Programming Style")
;; Customizations for all of c-mode, c++-mode, and objc-mode
(defun my-c-mode-common-hook ()
;; add my personal style and set it for the current buffer
(c-add-style "PERSONAL" my-c-style t)
;; offset customizations not in my-c-style
(c-set-offset 'defun-block-intro' +)
;; other customizations
;
(setq-default indent-tabs-mode nil)
;; make sure that comments don't get moved when you do a //
(c-set-offset 'comment-intro 0)
;; keybindings for all supported languages. We can put these in
;; c-mode-base-map because c-mode-map, c++-mode-map, objc-mode-map,
;; java-mode-map, and idl-mode-map inherit from it.
(define-key c-mode-base-map "\C-m" 'newline-and-indent)
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
(require 'php-mode)
[...]
令我感到困惑的是,使用C或C ++,emacs可以根据需要缩进我的代码,例如:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
[...]
if ((cond = strcmp(word, mid->word)) < 0) {
high = mid;
low = mid - 1;
} else if (cond > 0) {
low = mid + 1;
high = mid + 2;
} else
return mid;
}
我再次查看了CC模式手册,但无法弄清楚是什么导致emacs表现得如此。我做了典型的Cc Cs,合成元素也是PHP中的“语句”,所以为什么在PHP的情况下,emacs使用else中的'e'作为偏移计算的锚,但在C / C ++中,它使用结束支撑'}'应该如何?我会很感激任何提示和/或指示。
答案 0 :(得分:0)
你的问题遗失了{在其他人之后。 Emacs正在缩进,就像你继续其他人一样。添加{并且它将正常工作