0

无论模式如何,我都在编写一个取消注释的函数。我想删除行首的所有注释字符。

如何使下面的代码段循环,直到以下字符不等于注释开始?(所以基本上让这个“如果”继续下去,直到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))))
4

1 回答 1

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))
    )
)
于 2012-11-03T20:38:25.243 回答