emacs function to uncomment regardless of mode
16:10 14 Oct 2012

Main goal: making a smart "uncomment" function suitable for any mode.

(defun uncomment-mode-specific ()
  (interactive)
  (if (region-active-p)
      (comment-region (region-beginning) (region-end) -1)  ; so far so good
    (if (= ";" (line-beginning-position))                   ; here is the problem
         (message "successful")
       (message "unsuccessful"))
))

In the if statement, I would like to check for the value of the first character of the line, and if it equals the variable comment-start (which would return ";" in emacs lisp), goto beginning-of-line and delete the character. Ideas?

EDIT: More clarification as requested in a comment below follows. I would like a function to do:

1) If a region is selected, remove the comments (here that uncomment-region or comment-dwim would work as pointed out by Patrick)

ELSE:

2) If the first character of the line at point is a comment character, remove the comment character.

ELSE:

3) Search current line for comment (excluding \% or \;, mode dependent), move up to comment and kill the line starting with the comment sign.

I could not see how you would want this to work differently. It could then be bound to one key to simply remove comments, depending on the mode, using comment-start to identify the comment character.

emacs