all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Using comment characters for specific major modes
@ 2021-06-05 20:52 martin-kemp
  2021-06-05 21:50 ` Jean Louis
  2021-06-06  8:32 ` Omar Polo
  0 siblings, 2 replies; 30+ messages in thread
From: martin-kemp @ 2021-06-05 20:52 UTC (permalink / raw)
  To: help-gnu-emacs

Am using the following expression to make a line composed of ";" of length lena.



The first two semicolons ";;" are for when I use elisp code.



    (setq-local s (concat ";; " (make-string lena ?\;)))



But I want to change the starting ";;" to be the comment character of the major mode I am working with.



For texinfo I want "@c", and for fortran-mode I want "c", and "!!" for f90-mode.







^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Using comment characters for specific major modes
  2021-06-05 20:52 Using comment characters for specific major modes martin-kemp
@ 2021-06-05 21:50 ` Jean Louis
  2021-06-05 22:05   ` martin-kemp
  2021-06-06  8:32 ` Omar Polo
  1 sibling, 1 reply; 30+ messages in thread
From: Jean Louis @ 2021-06-05 21:50 UTC (permalink / raw)
  To: martin-kemp; +Cc: help-gnu-emacs

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-05 23:52]:
> Am using the following expression to make a line composed of ";" of length lena.
> 
> The first two semicolons ";;" are for when I use elisp code.
> 
>     (setq-local s (concat ";; " (make-string lena ?\;)))
> 
> But I want to change the starting ";;" to be the comment character
> of the major mode I am working with.
> 
> For texinfo I want "@c", and for fortran-mode I want "c", and "!!"
> for f90-mode.

Those things I would always use as a function. Possibility is
great that I misunderstand you due to short description of what
you want.

(defun my-fancy-thing ()
  (interactive)
  (let* ((initial (completing-read "Comment: " '("1 ;;" "2 !!") nil t))
	 (comment (substring initial 2))
	 (lena 10)
	 (string (make-string lena (string-to-char (substring initial 2)))))
    (insert (concat comment " " string))))

;; ;;;;;;;;;;

!! !!!!!!!!!!



-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Using comment characters for specific major modes
  2021-06-05 21:50 ` Jean Louis
@ 2021-06-05 22:05   ` martin-kemp
  2021-06-05 22:40     ` Jean Louis
  0 siblings, 1 reply; 30+ messages in thread
From: martin-kemp @ 2021-06-05 22:05 UTC (permalink / raw)
  To: Jean Louis; +Cc: help-gnu-emacs

I only want to change the first two, the rest remains the same



Suppose lena is 8


emacs-lisp-mode

;; ;;;;;;;;



f90-mode

!! ;;;;;;;;



fortran-mode

cc ;;;;;;;; 



texinfo-mode

@c ;;;;;;;;







From: Jean Louis <bugs@gnu.support>
To: martin-kemp@brusseler.com
Subject: Re: Using comment characters for specific major modes
Date: 05/06/2021 23:50:25 Europe/Paris
Cc: help-gnu-emacs@gnu.org

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-05 23:52]:
> Am using the following expression to make a line composed of ";" of length lena.
> 
> The first two semicolons ";;" are for when I use elisp code.
> 
>     (setq-local s (concat ";; " (make-string lena ?\;)))
> 
> But I want to change the starting ";;" to be the comment character
> of the major mode I am working with.
> 
> For texinfo I want "@c", and for fortran-mode I want "c", and "!!"
> for f90-mode.

Those things I would always use as a function. Possibility is
great that I misunderstand you due to short description of what
you want.

(defun my-fancy-thing ()
(interactive)
(let* ((initial (completing-read "Comment: " '("1 ;;" "2 !!") nil t))
(comment (substring initial 2))
(lena 10)
(string (make-string lena (string-to-char (substring initial 2)))))
(insert (concat comment " " string))))

;; ;;;;;;;;;;

!! !!!!!!!!!!



-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/




^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Using comment characters for specific major modes
  2021-06-05 22:05   ` martin-kemp
@ 2021-06-05 22:40     ` Jean Louis
  2021-06-05 22:53       ` martin-kemp
  0 siblings, 1 reply; 30+ messages in thread
From: Jean Louis @ 2021-06-05 22:40 UTC (permalink / raw)
  To: martin-kemp; +Cc: help-gnu-emacs

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 01:06]:
> I only want to change the first two, the rest remains the same
> 
> Suppose lena is 8


OK and how do you propose to change the function?

Instead:

(defun my-fancy-thing ()
  (interactive)
  (let* ((initial (completing-read "Comment: " '("1 ;;" "2 !!") nil t))
	 (comment (substring initial 2))
	 (lena 10)
	 (string (make-string lena (string-to-char (substring initial 2)))))
    (insert (concat comment " " string))))

then:

(defun my-fancy-thing ()
  (interactive)
  (let* ((initial (completing-read "Comment: " '("1 ;;" "2 !!") nil t))
	 (comment (substring initial 2))
	 (lena 10)
	 (string (make-string lena 59)))
    (insert (concat comment " " string))))

;; ;;;;;;;;;;

Adopt the function to your needs.



-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Using comment characters for specific major modes
  2021-06-05 22:40     ` Jean Louis
@ 2021-06-05 22:53       ` martin-kemp
  2021-06-05 23:05         ` Jean Louis
  0 siblings, 1 reply; 30+ messages in thread
From: martin-kemp @ 2021-06-05 22:53 UTC (permalink / raw)
  To: Jean Louis; +Cc: help-gnu-emacs

I would not like to use the mini-buffer, but introduce the comment character 

according the the major mode being used on the buffer.



Is there a command that gets the current comment for the major mode used in the

working buffer ?



Would use the comment character twice  ";;"',  "cc", "!!", except for texinfo which

will use just "@c" as it is already composed of two characters.



From: Jean Louis <bugs@gnu.support>
To: martin-kemp@brusseler.com
Subject: Re: Using comment characters for specific major modes
Date: 06/06/2021 00:40:14 Europe/Paris
Cc: help-gnu-emacs@gnu.org

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 01:06]:
> I only want to change the first two, the rest remains the same
> 
> Suppose lena is 8


OK and how do you propose to change the function?

Instead:

(defun my-fancy-thing ()
(interactive)
(let* ((initial (completing-read "Comment: " '("1 ;;" "2 !!") nil t))
(comment (substring initial 2))
(lena 10)
(string (make-string lena (string-to-char (substring initial 2)))))
(insert (concat comment " " string))))

then:

(defun my-fancy-thing ()
(interactive)
(let* ((initial (completing-read "Comment: " '("1 ;;" "2 !!") nil t))
(comment (substring initial 2))
(lena 10)
(string (make-string lena 59)))
(insert (concat comment " " string))))

;; ;;;;;;;;;;

Adopt the function to your needs.



-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/




^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Using comment characters for specific major modes
  2021-06-05 22:53       ` martin-kemp
@ 2021-06-05 23:05         ` Jean Louis
  2021-06-05 23:20           ` martin-kemp
  0 siblings, 1 reply; 30+ messages in thread
From: Jean Louis @ 2021-06-05 23:05 UTC (permalink / raw)
  To: martin-kemp; +Cc: help-gnu-emacs

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 01:54]:
> Is there a command that gets the current comment for the major mode
> used in the working buffer ?

M-;




-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Using comment characters for specific major modes
  2021-06-05 23:05         ` Jean Louis
@ 2021-06-05 23:20           ` martin-kemp
  2021-06-05 23:32             ` Jean Louis
  2021-06-06  3:24             ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 2 replies; 30+ messages in thread
From: martin-kemp @ 2021-06-05 23:20 UTC (permalink / raw)
  To: Jean Louis; +Cc: help-gnu-emacs


That uses the command (comment-dwim ARG), but I got to get the comment characters
to append to the string "s".



  (setq-local s (concat ";; " (make-string lena ?\;)))



At least that was my plan.  You may know the proper way to do it though.



From: Jean Louis <bugs@gnu.support>
To: martin-kemp@brusseler.com
Subject: Re: Using comment characters for specific major modes
Date: 06/06/2021 01:05:35 Europe/Paris
Cc: help-gnu-emacs@gnu.org

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 01:54]:
> Is there a command that gets the current comment for the major mode
> used in the working buffer ?

M-;




-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/




^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Using comment characters for specific major modes
  2021-06-05 23:20           ` martin-kemp
@ 2021-06-05 23:32             ` Jean Louis
  2021-06-05 23:47               ` martin-kemp
  2021-06-06  3:24             ` Stefan Monnier via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 30+ messages in thread
From: Jean Louis @ 2021-06-05 23:32 UTC (permalink / raw)
  To: martin-kemp; +Cc: help-gnu-emacs

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 02:21]:
> 
> That uses the command (comment-dwim ARG), but I got to get the comment characters
> to append to the string "s".
> 
> 
> 
>   (setq-local s (concat ";; " (make-string lena ?\;)))
> 
> 
> 
> At least that was my plan.  You may know the proper way to do it
> though.

Describe it better, it is to me unclear what you need.


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Using comment characters for specific major modes
  2021-06-05 23:32             ` Jean Louis
@ 2021-06-05 23:47               ` martin-kemp
  2021-06-05 23:56                 ` Jean Louis
  0 siblings, 1 reply; 30+ messages in thread
From: martin-kemp @ 2021-06-05 23:47 UTC (permalink / raw)
  To: Jean Louis; +Cc: help-gnu-emacs

Ok, let's try again.  I have a string "s" composed of repeating the character ";" lena times.

At the front I want to prepend the major mode comment character twice, except for texinfo-mode.



Initially "s" is ";;;;;;;;" when lena is 8



Then I will insert in the buffer the following 



emacs-lisp-mode

;; ;;;;;;;;



f90-mode

!! ;;;;;;;;



fortran-mode

cc ;;;;;;;;



texinfo-mode

@c ;;;;;;;;



To remove the confusion, suppose the character for "s" is "*" of length lena



Then I want to print



emacs-lisp-mode

;; ********



f90-mode

!! ********



fortran-mode

cc ********



texinfo-mode

@c ********





From: Jean Louis <bugs@gnu.support>
To: martin-kemp@brusseler.com
Subject: Re: Using comment characters for specific major modes
Date: 06/06/2021 01:32:09 Europe/Paris
Cc: help-gnu-emacs@gnu.org

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 02:21]:
> 
> That uses the command (comment-dwim ARG), but I got to get the comment characters
> to append to the string "s".
> 
> 
> 
>   (setq-local s (concat ";; " (make-string lena ?\;)))
> 
> 
> 
> At least that was my plan.  You may know the proper way to do it
> though.

Describe it better, it is to me unclear what you need.


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/




^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Using comment characters for specific major modes
  2021-06-05 23:47               ` martin-kemp
@ 2021-06-05 23:56                 ` Jean Louis
  2021-06-06  0:17                   ` martin-kemp
  0 siblings, 1 reply; 30+ messages in thread
From: Jean Louis @ 2021-06-05 23:56 UTC (permalink / raw)
  To: martin-kemp; +Cc: help-gnu-emacs

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 02:48]:
> Ok, let's try again.  I have a string "s" composed of repeating the character ";" lena times.
> 
> At the front I want to prepend the major mode comment character
> twice, except for texinfo-mode.

And what is preventing you?

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Using comment characters for specific major modes
  2021-06-05 23:56                 ` Jean Louis
@ 2021-06-06  0:17                   ` martin-kemp
  2021-06-06  0:23                     ` Jean Louis
  0 siblings, 1 reply; 30+ messages in thread
From: martin-kemp @ 2021-06-06  0:17 UTC (permalink / raw)
  To: Jean Louis; +Cc: help-gnu-emacs

The way you are using comment in



(comment (substring initial 2))



Does not like you are calling a function that introduces the comment characters,

particularly when I need twe next to each other.



I am thankful for your help but I am not getting it yet.


From: Jean Louis <bugs@gnu.support>
To: martin-kemp@brusseler.com
Subject: Re: Using comment characters for specific major modes
Date: 06/06/2021 01:56:06 Europe/Paris
Cc: help-gnu-emacs@gnu.org

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 02:48]:
> Ok, let's try again.  I have a string "s" composed of repeating the character ";" lena times.
> 
> At the front I want to prepend the major mode comment character
> twice, except for texinfo-mode.

And what is preventing you?

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/




^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Using comment characters for specific major modes
  2021-06-06  0:17                   ` martin-kemp
@ 2021-06-06  0:23                     ` Jean Louis
  2021-06-06  0:39                       ` martin-kemp
  0 siblings, 1 reply; 30+ messages in thread
From: Jean Louis @ 2021-06-06  0:23 UTC (permalink / raw)
  To: martin-kemp; +Cc: help-gnu-emacs

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 03:18]:
> The way you are using comment in
> (comment (substring initial 2))

As the above is incomplete sentence I cannot understand you. 

> Does not like you are calling a function that introduces the comment
> characters, particularly when I need twe next to each other.

Hard to understand. 

> I am thankful for your help but I am not getting it yet.

It's OK neither I get what it should be. Maybe we can try with lights
or music?

Reference:
https://www.imdb.com/title/tt0075860/mediaindex?ref_=tt_mv_close




-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Using comment characters for specific major modes
  2021-06-06  0:23                     ` Jean Louis
@ 2021-06-06  0:39                       ` martin-kemp
  2021-06-06  0:43                         ` Jean Louis
  0 siblings, 1 reply; 30+ messages in thread
From: martin-kemp @ 2021-06-06  0:39 UTC (permalink / raw)
  To: Jean Louis; +Cc: help-gnu-emacs

For emacs-lisp-mode I would like "s" to be

(setq-local s (concat ";; " (make-string lena ?\;)))



For texinfo-mode I would like "s" to be

(setq-local s (concat "@c " (make-string lena ?\;)))



For fortran-mode I would like "s" to be

(setq-local s (concat "cc " (make-string lena ?\;)))


For f90-mode I would like "s" to be

(setq-local s (concat "!! " (make-string lena ?\;)))


Finally I would insert the string "s".





Only the first two characters change at the beginning of the string "s".


From: Jean Louis <bugs@gnu.support>
To: martin-kemp@brusseler.com
Subject: Re: Using comment characters for specific major modes
Date: 06/06/2021 02:23:04 Europe/Paris
Cc: help-gnu-emacs@gnu.org

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 03:18]:
> The way you are using comment in
> (comment (substring initial 2))

As the above is incomplete sentence I cannot understand you. 

> Does not like you are calling a function that introduces the comment
> characters, particularly when I need twe next to each other.

Hard to understand. 

> I am thankful for your help but I am not getting it yet.

It's OK neither I get what it should be. Maybe we can try with lights
or music?

Reference:
https://www.imdb.com/title/tt0075860/mediaindex?ref_=tt_mv_close




-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/




^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Using comment characters for specific major modes
  2021-06-06  0:39                       ` martin-kemp
@ 2021-06-06  0:43                         ` Jean Louis
  2021-06-06  9:14                           ` martin-kemp
  0 siblings, 1 reply; 30+ messages in thread
From: Jean Louis @ 2021-06-06  0:43 UTC (permalink / raw)
  To: martin-kemp; +Cc: help-gnu-emacs

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 03:40]:
> For emacs-lisp-mode I would like "s" to be
> 
> (setq-local s (concat ";; " (make-string lena ?\;)))


(defun my-whatever ()
  (interactive)
  (let ((s (cond ((eq major-mode 'adoc-mode) (do something))
		 ((eq major-mode 'markdown-mode) (do something))
		 (t s))))
    (insert s)))

You may use `cond' function to test the variable `major-mode' and
accordingly return the value for `s' which you then insert in the
buffer.


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Using comment characters for specific major modes
  2021-06-05 23:20           ` martin-kemp
  2021-06-05 23:32             ` Jean Louis
@ 2021-06-06  3:24             ` Stefan Monnier via Users list for the GNU Emacs text editor
  2021-06-09 15:42               ` martin-kemp
  1 sibling, 1 reply; 30+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2021-06-06  3:24 UTC (permalink / raw)
  To: help-gnu-emacs

> That uses the command (comment-dwim ARG), but I got to get the comment characters
> to append to the string "s".
>
>   (setq-local s (concat ";; " (make-string lena ?\;)))
>
> At least that was my plan.  You may know the proper way to do it though.

Here's how you could go about finding the answer:

Seeing that `comment-dwim` manages to find the ";;" you're looking for,
you could look into it code: `C-h o comment-dwim RET` then click on the
link to jump to the definition.  There you'll see:

    [...]
    (comment-normalize-vars)
    (if (use-region-p)
        (comment-or-uncomment-region (region-beginning) (region-end) arg)
      (if (save-excursion (beginning-of-line) (not (looking-at "\\s-*$")))
          ;; FIXME: If there's no comment to kill on this line and ARG is
          ;; specified, calling comment-kill is not very clever.
          (if arg (comment-kill (and (integerp arg) arg)) (comment-indent))
        ;; Inserting a comment on a blank line. comment-indent calls
        ;; c-i-c-f if needed in the non-blank case.
        (if comment-insert-comment-function
            (funcall comment-insert-comment-function)
          (let ((add (comment-add arg)))
            ;; Some modes insist on keeping column 0 comment in column 0
            ;; so we need to move away from it before inserting the comment.
            (indent-according-to-mode)
            (insert (comment-padright comment-start add))
            (save-excursion
              (unless (string= "" comment-end)
                (insert (comment-padleft comment-end add)))
              (indent-according-to-mode)))))))

And here you already see some functions and variable which might give
you some answers, such as `comment-add`,
`comment-insert-comment-function`, `comment-start`, ...
Using `C-h o` on those should fairly quickly lead you to:

    comment-start is a variable defined in ‘newcomment.el’.
    Its value is ";"
    Local in buffer newcomment.el.gz; global value is nil
    
      This variable is safe as a file local variable if its value
      satisfies the predicate ‘string-or-null-p’.
      Probably introduced at or before Emacs version 21.1.
    
    Documentation:
    String to insert to start a new comment, or nil if no comment syntax.
    
    [back]


-- Stefan




^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Using comment characters for specific major modes
  2021-06-05 20:52 Using comment characters for specific major modes martin-kemp
  2021-06-05 21:50 ` Jean Louis
@ 2021-06-06  8:32 ` Omar Polo
  2021-06-06  8:34   ` Omar Polo
  1 sibling, 1 reply; 30+ messages in thread
From: Omar Polo @ 2021-06-06  8:32 UTC (permalink / raw)
  To: martin-kemp; +Cc: help-gnu-emacs


martin-kemp@brusseler.com writes:

> Am using the following expression to make a line composed of ";" of length lena.
>
>
>
> The first two semicolons ";;" are for when I use elisp code.
>
>
>
>     (setq-local s (concat ";; " (make-string lena ?\;)))
>
>
>
> But I want to change the starting ";;" to be the comment character of the major mode I am working with.
>
>
>
> For texinfo I want "@c", and for fortran-mode I want "c", and "!!" for f90-mode.

taking a look at how things like `comment-dwim' is quite educational.
The comment handling is easy but there are a few gotchas, like not all
major-modes have a single "comment string" (like ";" in Lisp), some have
starting and ending comment string (like C with /* and */)

I've come up with the following

--------8<--------
(defun insert-lena ()
  (interactive)
  (let* ((lena 8)
         (s (make-string lena ?\;)))
    ;; this bit is stolen from comment-dwim
    (if comment-insert-comment-function
        (funcall comment-insert-comment-function)
      (let ((add (comment-add nil)))
        (indent-according-to-mode)
        (insert (comment-padright comment-start add))
        (save-excursion
          (unless (string= "" comment-end)
            (insert (comment-padleft comment-end add)))
          (indent-according-to-mode))))
    ;; insert the string
    (insert s)))
-------->8--------

that seems to works.

It uses comment-insert-comment-function or comment-start/end.  I stolen
a bit from comment-dwim.

In lisps buffer it inserts

;; ;;;;;;;;

while in a C buffer it adds

/* ;;;;;;;; */

Probably it doesn't do exactly what you want, and there are probably
edge cases when there is a region active or things like that, but it's a
good start (I think).

HTH



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Using comment characters for specific major modes
  2021-06-06  8:32 ` Omar Polo
@ 2021-06-06  8:34   ` Omar Polo
  2021-06-06  9:05     ` martin-kemp
  0 siblings, 1 reply; 30+ messages in thread
From: Omar Polo @ 2021-06-06  8:34 UTC (permalink / raw)
  To: martin-kemp; +Cc: help-gnu-emacs

I've seen only now the reply from Stefan Monnier, which is (of course
:P) better than mine, apologies.  His explanation is indeed better.

Sorry for the noise.

Omar Polo <op@omarpolo.com> writes:

> martin-kemp@brusseler.com writes:
>
>> Am using the following expression to make a line composed of ";" of length lena.
>>
>>
>>
>> The first two semicolons ";;" are for when I use elisp code.
>>
>>
>>
>>     (setq-local s (concat ";; " (make-string lena ?\;)))
>>
>>
>>
>> But I want to change the starting ";;" to be the comment character of the major mode I am working with.
>>
>>
>>
>> For texinfo I want "@c", and for fortran-mode I want "c", and "!!" for f90-mode.
>
> taking a look at how things like `comment-dwim' is quite educational.
> The comment handling is easy but there are a few gotchas, like not all
> major-modes have a single "comment string" (like ";" in Lisp), some have
> starting and ending comment string (like C with /* and */)
>
> I've come up with the following
>
> --------8<--------
> (defun insert-lena ()
>   (interactive)
>   (let* ((lena 8)
>          (s (make-string lena ?\;)))
>     ;; this bit is stolen from comment-dwim
>     (if comment-insert-comment-function
>         (funcall comment-insert-comment-function)
>       (let ((add (comment-add nil)))
>         (indent-according-to-mode)
>         (insert (comment-padright comment-start add))
>         (save-excursion
>           (unless (string= "" comment-end)
>             (insert (comment-padleft comment-end add)))
>           (indent-according-to-mode))))
>     ;; insert the string
>     (insert s)))
> -------->8--------
>
> that seems to works.
>
> It uses comment-insert-comment-function or comment-start/end.  I stolen
> a bit from comment-dwim.
>
> In lisps buffer it inserts
>
> ;; ;;;;;;;;
>
> while in a C buffer it adds
>
> /* ;;;;;;;; */
>
> Probably it doesn't do exactly what you want, and there are probably
> edge cases when there is a region active or things like that, but it's a
> good start (I think).
>
> HTH




^ permalink raw reply	[flat|nested] 30+ messages in thread

* Using comment characters for specific major modes
  2021-06-06  8:34   ` Omar Polo
@ 2021-06-06  9:05     ` martin-kemp
  2021-06-06 11:43       ` Omar Polo
  0 siblings, 1 reply; 30+ messages in thread
From: martin-kemp @ 2021-06-06  9:05 UTC (permalink / raw)
  To: Omar Polo; +Cc: help-gnu-emacs

I would find it useful if there was a function that returns a list with the comment delimiter 

for the specific mode.  Then one can select which one to get.



From: Omar Polo <op@omarpolo.com>
To: martin-kemp@brusseler.com
Subject: Re: Using comment characters for specific major modes
Date: 06/06/2021 10:34:12 Europe/Paris
Cc: help-gnu-emacs@gnu.org

I've seen only now the reply from Stefan Monnier, which is (of course
:P) better than mine, apologies. His explanation is indeed better.

Sorry for the noise.

Omar Polo <op@omarpolo.com> writes:

> martin-kemp@brusseler.com writes:
>
>> Am using the following expression to make a line composed of ";" of length lena.
>>
>>
>>
>> The first two semicolons ";;" are for when I use elisp code.
>>
>>
>>
>> (setq-local s (concat ";; " (make-string lena ?\;)))
>>
>>
>>
>> But I want to change the starting ";;" to be the comment character of the major mode I am working with.
>>
>>
>>
>> For texinfo I want "@c", and for fortran-mode I want "c", and "!!" for f90-mode.
>
> taking a look at how things like `comment-dwim' is quite educational.
> The comment handling is easy but there are a few gotchas, like not all
> major-modes have a single "comment string" (like ";" in Lisp), some have
> starting and ending comment string (like C with /* and */)
>
> I've come up with the following
>
> --------8<--------
> (defun insert-lena ()
> (interactive)
> (let* ((lena 8)
> (s (make-string lena ?\;)))
> ;; this bit is stolen from comment-dwim
> (if comment-insert-comment-function
> (funcall comment-insert-comment-function)
> (let ((add (comment-add nil)))
> (indent-according-to-mode)
> (insert (comment-padright comment-start add))
> (save-excursion
> (unless (string= "" comment-end)
> (insert (comment-padleft comment-end add)))
> (indent-according-to-mode))))
> ;; insert the string
> (insert s)))
> -------->8--------
>
> that seems to works.
>
> It uses comment-insert-comment-function or comment-start/end. I stolen
> a bit from comment-dwim.
>
> In lisps buffer it inserts
>
> ;; ;;;;;;;;
>
> while in a C buffer it adds
>
> /* ;;;;;;;; */
>
> Probably it doesn't do exactly what you want, and there are probably
> edge cases when there is a region active or things like that, but it's a
> good start (I think).
>
> HTH




^ permalink raw reply	[flat|nested] 30+ messages in thread

* Using comment characters for specific major modes
  2021-06-06  0:43                         ` Jean Louis
@ 2021-06-06  9:14                           ` martin-kemp
  2021-06-06  9:46                             ` Jean Louis
  2021-06-06 16:02                             ` Stefan Möding
  0 siblings, 2 replies; 30+ messages in thread
From: martin-kemp @ 2021-06-06  9:14 UTC (permalink / raw)
  To: Jean Louis; +Cc: help-gnu-emacs

You have been most helpful.  Others have given me other ways but have found them too complicated 

for me.  Forget using comment type functions, I will just set the variable "cm" directly.



I am almost there.  I have now done



   (let ((cm (cond ((eq major-mode 'emacs-lisp-mode) (do something))
           ((eq major-mode 'texinfo-mode)    (do something))
           ((eq major-mode 'f90-mode)        (do something))
           ((eq major-mode 'fortran-mode)    (do something))



What I need is to set "cm" to ";;" for 'emacs-lisp-mode, "@c" for texinfo-mode etc.



Have difficulty setting "cm" though.





From: Jean Louis <bugs@gnu.support>
To: martin-kemp@brusseler.com
Subject: Re: Using comment characters for specific major modes
Date: 06/06/2021 02:43:58 Europe/Paris
Cc: help-gnu-emacs@gnu.org

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 03:40]:
> For emacs-lisp-mode I would like "s" to be
> 
> (setq-local s (concat ";; " (make-string lena ?\;)))


(defun my-whatever ()
(interactive)
(let ((s (cond ((eq major-mode 'adoc-mode) (do something))
((eq major-mode 'markdown-mode) (do something))
(t s))))
(insert s)))

You may use `cond' function to test the variable `major-mode' and
accordingly return the value for `s' which you then insert in the
buffer.


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Using comment characters for specific major modes
  2021-06-06  9:14                           ` martin-kemp
@ 2021-06-06  9:46                             ` Jean Louis
  2021-06-06 16:02                             ` Stefan Möding
  1 sibling, 0 replies; 30+ messages in thread
From: Jean Louis @ 2021-06-06  9:46 UTC (permalink / raw)
  To: martin-kemp; +Cc: help-gnu-emacs

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 12:14]:
>    (let ((cm (cond ((eq major-mode 'emacs-lisp-mode) (do something))
>            ((eq major-mode 'texinfo-mode)    (do something))
>            ((eq major-mode 'f90-mode)        (do something))
>            ((eq major-mode 'fortran-mode)    (do something))
> 
> 
> 
> What I need is to set "cm" to ";;" for 'emacs-lisp-mode, "@c" for texinfo-mode etc.
> Have difficulty setting "cm" though.

(setq cm ";;")

so you have to replace (do something) with the code you need.


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Using comment characters for specific major modes
  2021-06-06  9:05     ` martin-kemp
@ 2021-06-06 11:43       ` Omar Polo
  0 siblings, 0 replies; 30+ messages in thread
From: Omar Polo @ 2021-06-06 11:43 UTC (permalink / raw)
  To: martin-kemp; +Cc: help-gnu-emacs


martin-kemp@brusseler.com writes:

> I would find it useful if there was a function that returns a list with the comment delimiter 
>
> for the specific mode.  Then one can select which one to get.

I don't have a deep knowledge (or any knowledge at all really).
Studiyng newcomment.el is probably the way to go, but as you can see
from comment-dwim there are two variables `comment-start' and
`comment-end' that holds the string for the start and end string of
comments.

They are respectively ";" and "" in elisp-mode, or "/*" and "*/" in
c-mode, and so on.

> From: Omar Polo <op@omarpolo.com>
> To: martin-kemp@brusseler.com
> Subject: Re: Using comment characters for specific major modes
> Date: 06/06/2021 10:34:12 Europe/Paris
> Cc: help-gnu-emacs@gnu.org
>
> I've seen only now the reply from Stefan Monnier, which is (of course
> :P) better than mine, apologies. His explanation is indeed better.
>
> Sorry for the noise.
>
> Omar Polo <op@omarpolo.com> writes:
>
>> martin-kemp@brusseler.com writes:
>>
>>> Am using the following expression to make a line composed of ";" of length lena.
>>>
>>>
>>>
>>> The first two semicolons ";;" are for when I use elisp code.
>>>
>>>
>>>
>>> (setq-local s (concat ";; " (make-string lena ?\;)))
>>>
>>>
>>>
>>> But I want to change the starting ";;" to be the comment character of the major mode I am working with.
>>>
>>>
>>>
>>> For texinfo I want "@c", and for fortran-mode I want "c", and "!!" for f90-mode.
>>
>> taking a look at how things like `comment-dwim' is quite educational.
>> The comment handling is easy but there are a few gotchas, like not all
>> major-modes have a single "comment string" (like ";" in Lisp), some have
>> starting and ending comment string (like C with /* and */)
>>
>> I've come up with the following
>>
>> --------8<--------
>> (defun insert-lena ()
>> (interactive)
>> (let* ((lena 8)
>> (s (make-string lena ?\;)))
>> ;; this bit is stolen from comment-dwim
>> (if comment-insert-comment-function
>> (funcall comment-insert-comment-function)
>> (let ((add (comment-add nil)))
>> (indent-according-to-mode)
>> (insert (comment-padright comment-start add))
>> (save-excursion
>> (unless (string= "" comment-end)
>> (insert (comment-padleft comment-end add)))
>> (indent-according-to-mode))))
>> ;; insert the string
>> (insert s)))
>> -------->8--------
>>
>> that seems to works.
>>
>> It uses comment-insert-comment-function or comment-start/end. I stolen
>> a bit from comment-dwim.
>>
>> In lisps buffer it inserts
>>
>> ;; ;;;;;;;;
>>
>> while in a C buffer it adds
>>
>> /* ;;;;;;;; */
>>
>> Probably it doesn't do exactly what you want, and there are probably
>> edge cases when there is a region active or things like that, but it's a
>> good start (I think).
>>
>> HTH




^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Using comment characters for specific major modes
  2021-06-06  9:14                           ` martin-kemp
  2021-06-06  9:46                             ` Jean Louis
@ 2021-06-06 16:02                             ` Stefan Möding
  2021-06-06 16:23                               ` martin-kemp
  1 sibling, 1 reply; 30+ messages in thread
From: Stefan Möding @ 2021-06-06 16:02 UTC (permalink / raw)
  To: help-gnu-emacs

martin-kemp@brusseler.com writes:

> What I need is to set "cm" to ";;" for 'emacs-lisp-mode, "@c" for
> texinfo-mode etc.

The value returned by the cond form is the value of the selected cond
clause.  You can use the literals without calling any additional code:

(let ((cm (cond ((eq major-mode 'emacs-lisp-mode) ";;")
                ((eq major-mode 'texinfo-mode)    "@c")
                ...

Remember that `cm' will be nil if nothing was matched.

-- 
Stefan



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Using comment characters for specific major modes
  2021-06-06 16:02                             ` Stefan Möding
@ 2021-06-06 16:23                               ` martin-kemp
  2021-06-06 16:40                                 ` Jean Louis
  2021-06-06 16:56                                 ` Jean Louis
  0 siblings, 2 replies; 30+ messages in thread
From: martin-kemp @ 2021-06-06 16:23 UTC (permalink / raw)
  To: Stefan Möding, help-gnu-emacs

I am encountering tho problem you are mentioning.  "cs" stays at nil.





   (let (cs)
     (cond 

       ((eq major-mode 'emacs-lisp-mode) ";;")
       ((eq major-mode 'texinfo-mode)    "@c")
       ((eq major-mode 'f90-mode)        "!!")
       ((eq major-mode 'fortran-mode)    "cc"))

     (let* ( (m 62) (n 69)
         (lena (- m (current-column)))
         (lenb (- n (current-column))) )

       (message "cs: %s" cs)
       
       (pcase k
     (0
          ;; makes s to be line with repeating ";" lena times
      (setq-local s (concat cs " " (make-string lena ?\;)))
      (my-insert s k)
          (setq-local k 1))











From: Stefan Möding <s.moeding@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Using comment characters for specific major modes
Date: 06/06/2021 18:02:20 Europe/Paris

martin-kemp@brusseler.com writes:

> What I need is to set "cm" to ";;" for 'emacs-lisp-mode, "@c" for
> texinfo-mode etc.

The value returned by the cond form is the value of the selected cond
clause. You can use the literals without calling any additional code:

(let ((cm (cond ((eq major-mode 'emacs-lisp-mode) ";;")
((eq major-mode 'texinfo-mode) "@c")
...

Remember that `cm' will be nil if nothing was matched.

-- 
Stefan




^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Using comment characters for specific major modes
  2021-06-06 16:23                               ` martin-kemp
@ 2021-06-06 16:40                                 ` Jean Louis
  2021-06-06 16:53                                   ` martin-kemp
  2021-06-06 16:56                                 ` Jean Louis
  1 sibling, 1 reply; 30+ messages in thread
From: Jean Louis @ 2021-06-06 16:40 UTC (permalink / raw)
  To: martin-kemp; +Cc: Stefan Möding, help-gnu-emacs

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 19:23]:
> I am encountering tho problem you are mentioning.  "cs" stays at nil.

(let (cs)
     1
     cs) ⇒ nil

This is because there was no assignment of value 1 to variable
cs. Value 1 was just evaluated as such. 

(let ((cs 1)) ;; this is assignment of value 1 to variable cs
     cs) ⇒ 1



-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Using comment characters for specific major modes
  2021-06-06 16:40                                 ` Jean Louis
@ 2021-06-06 16:53                                   ` martin-kemp
  0 siblings, 0 replies; 30+ messages in thread
From: martin-kemp @ 2021-06-06 16:53 UTC (permalink / raw)
  To: Jean Louis; +Cc: Stefan Möding, help-gnu-emacs

This is getting very confusing again.



I would like "cs" to be ";;"' "@c", "!!", "cc"' according to the major mode.

Thought I could declare  "cs" without setting it.






From: Jean Louis <bugs@gnu.support>
To: martin-kemp@brusseler.com
Subject: Re: Using comment characters for specific major modes
Date: 06/06/2021 18:40:15 Europe/Paris
Cc: Stefan Möding <s.moeding@gmail.com>;
   help-gnu-emacs@gnu.org

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 19:23]:
> I am encountering tho problem you are mentioning.  "cs" stays at nil.

(let (cs)
1
cs) ⇒ nil

This is because there was no assignment of value 1 to variable
cs. Value 1 was just evaluated as such. 

(let ((cs 1)) ;; this is assignment of value 1 to variable cs
cs) ⇒ 1



-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/




^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Using comment characters for specific major modes
  2021-06-06 16:23                               ` martin-kemp
  2021-06-06 16:40                                 ` Jean Louis
@ 2021-06-06 16:56                                 ` Jean Louis
  2021-06-06 17:36                                   ` martin-kemp
  1 sibling, 1 reply; 30+ messages in thread
From: Jean Louis @ 2021-06-06 16:56 UTC (permalink / raw)
  To: martin-kemp; +Cc: Stefan Möding, help-gnu-emacs

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 19:23]:
>    (let (cs)  ;; ok I think it is declared but nil
>      (cond 
> 
>        ((eq major-mode 'emacs-lisp-mode) ";;")
>        ((eq major-mode 'texinfo-mode)    "@c")
>        ((eq major-mode 'f90-mode)        "!!")
>        ((eq major-mode 'fortran-mode)    "cc"))  ;;; this evaluates
>                                           ;; to comments but 
                                            ;; does not assign it 
                                            ;; to variable


This form begin would assign evaluation from `cond' to variable `cs':

(let ((cs (cond 


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Using comment characters for specific major modes
  2021-06-06 16:56                                 ` Jean Louis
@ 2021-06-06 17:36                                   ` martin-kemp
  2021-06-06 20:50                                     ` Jean Louis
  0 siblings, 1 reply; 30+ messages in thread
From: martin-kemp @ 2021-06-06 17:36 UTC (permalink / raw)
  To: Jean Louis; +Cc: Stefan Möding, help-gnu-emacs

I understand better now, you try to set "cs" in the "let" using cond.



Am still getting nil though.  Have changed the code somewhat.



   (let* ( (m 62) (n 69)
       (lena (- m (current-column)))
       (cs   (cond ((eq major-mode 'emacs-lisp-mode) ";;")
               ((eq major-mode 'texinfo-mode)    "@c")
               ((eq major-mode 'f90-mode)        "!!")
               ((eq major-mode 'fortran-mode)    "cc"))) )



(messsage "cs: %s" cs))









From: Jean Louis <bugs@gnu.support>
To: martin-kemp@brusseler.com
Subject: Re: Using comment characters for specific major modes
Date: 06/06/2021 18:56:46 Europe/Paris
Cc: Stefan Möding <s.moeding@gmail.com>;
   help-gnu-emacs@gnu.org

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 19:23]:
>    (let (cs) ;; ok I think it is declared but nil
>      (cond 
> 
>        ((eq major-mode 'emacs-lisp-mode) ";;")
>        ((eq major-mode 'texinfo-mode)    "@c")
>        ((eq major-mode 'f90-mode)        "!!")
>        ((eq major-mode 'fortran-mode)    "cc")) ;;; this evaluates
> ;; to comments but 
;; does not assign it 
;; to variable


This form begin would assign evaluation from `cond' to variable `cs':

(let ((cs (cond 


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/




^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Using comment characters for specific major modes
  2021-06-06 17:36                                   ` martin-kemp
@ 2021-06-06 20:50                                     ` Jean Louis
  2021-06-08  9:14                                       ` martin-kemp
  0 siblings, 1 reply; 30+ messages in thread
From: Jean Louis @ 2021-06-06 20:50 UTC (permalink / raw)
  To: martin-kemp; +Cc: Stefan Möding, help-gnu-emacs

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 20:37]:
> I understand better now, you try to set "cs" in the "let" using cond.
> 
> 
> 
> Am still getting nil though.  Have changed the code somewhat.

(defun my-cs ()
  (let* ((m 62)
	 (n 69)
	 (lena (- m (current-column)))
	 (cs (cond ((eq major-mode 'emacs-lisp-mode) ";;")
		   ((eq major-mode 'texinfo-mode) "@c")
		   ((eq major-mode 'f90-mode) "!!")
		   ((eq major-mode 'fortran-mode)"cc"))))
    cs))

(my-cs) ⇒ ";;"

It works, as I turnedd on emacs-lisp mode.


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Using comment characters for specific major modes
  2021-06-06 20:50                                     ` Jean Louis
@ 2021-06-08  9:14                                       ` martin-kemp
  0 siblings, 0 replies; 30+ messages in thread
From: martin-kemp @ 2021-06-08  9:14 UTC (permalink / raw)
  To: Jean Louis; +Cc: Stefan Möding, help-gnu-emacs

Might have found a problem when trying it in the scratch buffer.


From: Jean Louis <bugs@gnu.support>
To: martin-kemp@brusseler.com
Subject: Re: Using comment characters for specific major modes
Date: 06/06/2021 22:50:39 Europe/Paris
Cc: Stefan Möding <s.moeding@gmail.com>;
   help-gnu-emacs@gnu.org

* martin-kemp@brusseler.com <martin-kemp@brusseler.com> [2021-06-06 20:37]:
> I understand better now, you try to set "cs" in the "let" using cond.
> 
> 
> 
> Am still getting nil though.  Have changed the code somewhat.

(defun my-cs ()
(let* ((m 62)
(n 69)
(lena (- m (current-column)))
(cs (cond ((eq major-mode 'emacs-lisp-mode) ";;")
((eq major-mode 'texinfo-mode) "@c")
((eq major-mode 'f90-mode) "!!")
((eq major-mode 'fortran-mode)"cc"))))
cs))

(my-cs) ⇒ ";;"

It works, as I turnedd on emacs-lisp mode.


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/




^ permalink raw reply	[flat|nested] 30+ messages in thread

* Using comment characters for specific major modes
  2021-06-06  3:24             ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2021-06-09 15:42               ` martin-kemp
  0 siblings, 0 replies; 30+ messages in thread
From: martin-kemp @ 2021-06-09 15:42 UTC (permalink / raw)
  To: monnier, help-gnu-emacs

I have found it easier to use a condition depending on the major mode of the buffer to set the comment

prefix directly.






From: Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Using comment characters for specific major modes
Date: 06/06/2021 05:24:13 Europe/Paris

> That uses the command (comment-dwim ARG), but I got to get the comment characters
> to append to the string "s".
>
>   (setq-local s (concat ";; " (make-string lena ?\;)))
>
> At least that was my plan.  You may know the proper way to do it though.

Here's how you could go about finding the answer:

Seeing that `comment-dwim` manages to find the ";;" you're looking for,
you could look into it code: `C-h o comment-dwim RET` then click on the
link to jump to the definition. There you'll see:

[...]
(comment-normalize-vars)
(if (use-region-p)
(comment-or-uncomment-region (region-beginning) (region-end) arg)
(if (save-excursion (beginning-of-line) (not (looking-at "\\s-*$")))
;; FIXME: If there's no comment to kill on this line and ARG is
;; specified, calling comment-kill is not very clever.
(if arg (comment-kill (and (integerp arg) arg)) (comment-indent))
;; Inserting a comment on a blank line. comment-indent calls
;; c-i-c-f if needed in the non-blank case.
(if comment-insert-comment-function
(funcall comment-insert-comment-function)
(let ((add (comment-add arg)))
;; Some modes insist on keeping column 0 comment in column 0
;; so we need to move away from it before inserting the comment.
(indent-according-to-mode)
(insert (comment-padright comment-start add))
(save-excursion
(unless (string= "" comment-end)
(insert (comment-padleft comment-end add)))
(indent-according-to-mode)))))))

And here you already see some functions and variable which might give
you some answers, such as `comment-add`,
`comment-insert-comment-function`, `comment-start`, ...
Using `C-h o` on those should fairly quickly lead you to:

comment-start is a variable defined in ‘newcomment.el’.
Its value is ";"
Local in buffer newcomment.el.gz; global value is nil

This variable is safe as a file local variable if its value
satisfies the predicate ‘string-or-null-p’.
Probably introduced at or before Emacs version 21.1.

Documentation:
String to insert to start a new comment, or nil if no comment syntax.

[back]


-- Stefan





^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2021-06-09 15:42 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-05 20:52 Using comment characters for specific major modes martin-kemp
2021-06-05 21:50 ` Jean Louis
2021-06-05 22:05   ` martin-kemp
2021-06-05 22:40     ` Jean Louis
2021-06-05 22:53       ` martin-kemp
2021-06-05 23:05         ` Jean Louis
2021-06-05 23:20           ` martin-kemp
2021-06-05 23:32             ` Jean Louis
2021-06-05 23:47               ` martin-kemp
2021-06-05 23:56                 ` Jean Louis
2021-06-06  0:17                   ` martin-kemp
2021-06-06  0:23                     ` Jean Louis
2021-06-06  0:39                       ` martin-kemp
2021-06-06  0:43                         ` Jean Louis
2021-06-06  9:14                           ` martin-kemp
2021-06-06  9:46                             ` Jean Louis
2021-06-06 16:02                             ` Stefan Möding
2021-06-06 16:23                               ` martin-kemp
2021-06-06 16:40                                 ` Jean Louis
2021-06-06 16:53                                   ` martin-kemp
2021-06-06 16:56                                 ` Jean Louis
2021-06-06 17:36                                   ` martin-kemp
2021-06-06 20:50                                     ` Jean Louis
2021-06-08  9:14                                       ` martin-kemp
2021-06-06  3:24             ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-06-09 15:42               ` martin-kemp
2021-06-06  8:32 ` Omar Polo
2021-06-06  8:34   ` Omar Polo
2021-06-06  9:05     ` martin-kemp
2021-06-06 11:43       ` Omar Polo

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.