Я использую GNU Emacs 22.2.1 на ноутбуке HP с Ubuntu 9.04 с последними исправлениями.
В последнее время мне нужно обработать некоторые PHP-коды, поэтому я добавил пакет php-mode в Ubuntu, полагая, что то, что у меня есть в .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()
Обратите внимание, что оба комментария и оператор печати смещены на 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 использует «e» в else как якорь для вычисления смещения, но в C / C ++ он использует закрывающая скобка '}' как следует? Буду признателен за любые советы и / или указатели.