无论模式如何,我都在编写一个取消注释的功能。我想删除一行开头的所有注释字符。
如果以下字符不等于comment-start,我如何将代码段设置为循环? (所以基本上这个“如果”继续,直到following-char
不再等于comment-start
)
(if (string= (byte-to-string (following-char)) comment-start)
(progn (delete-forward-char 1)
(when (string= (byte-to-string (following-char)) " ")
(delete-forward-char 1))))
答案 0 :(得分:0)
while循环比我想象的容易:
(defun uncomment-mode-specific ()
"Uncomment region OR uncomment beginning of line comment OR uncomment end"
(interactive)
(if (region-active-p)
(uncomment-region (region-beginning) (region-end))
(back-to-indentation))
(setq scvar 0)
(setq scskipvar 0)
(while (= scvar 0)
(if (string= (byte-to-string (following-char)) comment-start)
(progn (delete-forward-char 1)
(when (string= (byte-to-string (following-char)) " ")
(delete-forward-char 1))
(setq scskipvar 1))
(setq scvar 1)))
(if (= scskipvar 0)
(progn (search-forward comment-start nil t)
(left-char 1)
(kill-line))
)
)