English 中文(简体)
如何配置 emacs 来在php- mode 中正确批注代码?
原标题:How to configure emacs to properly comment code in php-mode?

我有23.3.1的肿块,在窗户上跑来跑去。

php-mode 1.5 from http://php-mode.sourceforge.net/, Modified: 2008-11-04

I think this used to work, but now, when I try to comment out a block of code, using comment-region, which is an interactive compiled Lisp function in `newcomment.el , I get poor results.

示例:

之前:

""https://i.sstatic.net/RrDGDDD.png" alt="此处输入图像描述"/ >

之后:

""https://i.sstatic.net/THVVVE.png" Alt="此处的内置图像描述"/ >

您可以看到,注释区块中的每行都有单行注释启动序列 // ,多行注释终端序列 /

这不是一个大问题, 虽然它很丑。 当我想解开这个区块时, 问题就会出现。 我有一个错误, “ 找不到注释结尾 ” 。 换句话说, “ code> comment- region 无法用 < code> C- u vote- region 来反转 。

我看看我能不能弄明白 但有哪一种情况我在php-mode中漏掉了吗?

有人知道吗?


< 强 > MORE

我并没有在我的php-mode-hook 函数中设置任何内容来更改 comment- start comment-end 变量。 当我调试 comment-region 区域时,我可以看到这些变量被设置为 / 等不匹配的一对。 这解释了批注区域的怪异结果。 我不相信我的代码会设置这样的变量 。

我在钩子中尝试了将它们明确设置为 // 和 (空字符串) 。 在此情况下, comment-region 看上去更漂亮, 但仍然不难理解。 我也尝试了匹配的 / / code > 和 的对,但结果相同。 commission不成功; 错误是 无法找到注释结尾 。

<强 > MORE2

我认为我的语法表是正确的,它显示:

""https://i.sstatic.net/PKPTf.png" alt="此处输入图像描述"/ >

...在我看来是对的

最佳回答

这解决了它对我来说:

(setq comment-use-syntax t)

我把它放在我的php -mode钩。

不清楚是否有必要这样做,但我还加入了修改语法表的语句。整个钩子看起来是这样的:

(defun cheeso-php-mode-fn ()
  "Function to run when php-mode is initialized for a buffer."
  (require  flymake)
  (flymake-mode 1)

  (setq c-default-style "bsd"
      c-basic-offset 2)

  ;; not sure if necessary or not.
  (modify-syntax-entry ?/ ". 124b" php-mode-syntax-table)
  (modify-syntax-entry ?* ". 23" php-mode-syntax-table)
  (modify-syntax-entry ?
 "> b"  php-mode-syntax-table)
  (modify-syntax-entry ?^m "> b" php-mode-syntax-table)

  (setq comment-multi-line nil ;; maybe
        comment-start "// "
        comment-end ""
        comment-style  indent
        comment-use-syntax t))

The help statement for comment-use-syntax says that major modes should set it. In the php buffer I was editing, the variable was set to nil. I m guessing it was set by php-mode; in any case it was not set by me. Setting this to t and insuring that the syntax table had the appropriate values did the trick.

我应该说,我只在php中使用C型评论;我不使用

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...