Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8706139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:32:30+00:00 2026-06-13T03:32:30+00:00

Main goal: making a smart uncomment function suitable for any mode. (defun uncomment-mode-specific ()

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:32:31+00:00Added an answer on June 13, 2026 at 3:32 am

    I’m posting this as an alternative answer, since what you are trying to do is partly done already with the comment-dwim command. From the docs (you can find it using C-h f comment-dwim)

    comment-dwim is an interactive compiled Lisp function in
    `newcomment.el’.

    It is bound to M-;.

    (comment-dwim ARG)

    Call the comment command you want (Do What I Mean).
    If the region is active and transient-mark-mode is on, call
    comment-region (unless it only consists of comments, in which
    case it calls uncomment-region).
    Else, if the current line is empty, call comment-insert-comment-function
    if it is defined, otherwise insert a comment and indent it.
    Else if a prefix ARG is specified, call comment-kill.
    Else, call comment-indent.
    You can configure comment-style to change the way regions are commented.

    So in order to use it, simply select a region with C-SPC (set-mark-command) and move the caret to the other point and run comment-dwim.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The main goal of my issue is to put specific colors on Donut Change.
I have an application thats main goal is to play a specific video file.
My main goal: Collect specific information through the linux server on a windows machine.
My main goal is to change the volume on one sound card based on
How do i do that? Actually my main goal is to get which checkbox
For homework, I need to build a small java application.The main goal is to
I've recently started my new private project. The main goal which I want to
Is there a Maven phase or goal to simply execute the main method of
My main goal with this question is optimization and faster run time. After doing
My main goal: if the user selects a directory it scans the whole folder

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.