unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* /* */ style comments in C++ sources
@ 2017-05-23 18:57 Eli Zaretskii
  2017-05-23 20:31 ` Alan Mackenzie
  2017-05-24  9:08 ` Dani Moncayo
  0 siblings, 2 replies; 29+ messages in thread
From: Eli Zaretskii @ 2017-05-23 18:57 UTC (permalink / raw)
  To: emacs-devel; +Cc: Alan Mackenzie

Is there a way to tell Emacs to use the C-style comments in C++
sources?  (I couldn't find that in the CC Mode manual.)

TIA



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

* Re: /* */ style comments in C++ sources
  2017-05-23 18:57 /* */ style comments in C++ sources Eli Zaretskii
@ 2017-05-23 20:31 ` Alan Mackenzie
  2017-05-24  0:02   ` Richard Stallman
                     ` (2 more replies)
  2017-05-24  9:08 ` Dani Moncayo
  1 sibling, 3 replies; 29+ messages in thread
From: Alan Mackenzie @ 2017-05-23 20:31 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Hello, Eli.

On Tue, May 23, 2017 at 21:57:17 +0300, Eli Zaretskii wrote:
> Is there a way to tell Emacs to use the C-style comments in C++
> sources?  (I couldn't find that in the CC Mode manual.)

No, there is no (reasonable) way to tell CC Mode what style of comments
one prefers.

People have asked about this before.  It seems like it would be a useful
facility to add.  Though it might take a surprisingly large amount of
work to implement.

I'll think about it.

> TIA

-- 
Alan Mackenzie (Nuremberg, Germany).



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

* Re: /* */ style comments in C++ sources
  2017-05-23 20:31 ` Alan Mackenzie
@ 2017-05-24  0:02   ` Richard Stallman
  2017-05-24 20:36     ` Sam Steingold
  2017-05-24  2:27   ` Eli Zaretskii
  2017-05-24 17:19   ` John Mastro
  2 siblings, 1 reply; 29+ messages in thread
From: Richard Stallman @ 2017-05-24  0:02 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: eliz, emacs-devel

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > People have asked about this before.  It seems like it would be a useful
  > facility to add.  Though it might take a surprisingly large amount of
  > work to implement.

If we had a user option to control it, you could specify that
in the -*- line or the local variables list.

Is it hard to make a clean simple user option to control it?

-- 
Dr Richard Stallman
President, Free Software Foundation (gnu.org, fsf.org)
Internet Hall-of-Famer (internethalloffame.org)
Skype: No way! See stallman.org/skype.html.




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

* Re: /* */ style comments in C++ sources
  2017-05-23 20:31 ` Alan Mackenzie
  2017-05-24  0:02   ` Richard Stallman
@ 2017-05-24  2:27   ` Eli Zaretskii
  2017-05-24 20:53     ` Alan Mackenzie
  2017-05-24 17:19   ` John Mastro
  2 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2017-05-24  2:27 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: emacs-devel

> Date: Tue, 23 May 2017 20:31:44 +0000
> Cc: emacs-devel@gnu.org
> From: Alan Mackenzie <acm@muc.de>
> 
> On Tue, May 23, 2017 at 21:57:17 +0300, Eli Zaretskii wrote:
> > Is there a way to tell Emacs to use the C-style comments in C++
> > sources?  (I couldn't find that in the CC Mode manual.)
> 
> No, there is no (reasonable) way to tell CC Mode what style of comments
> one prefers.
> 
> People have asked about this before.  It seems like it would be a useful
> facility to add.

Indeed, it would.  The rationale for me is projects like GDB, which
switched from C to C++, but still prefer C-style comments for some
reason.  (Maybe GCC also prefers that, I don't know.)

> Though it might take a surprisingly large amount of work to
> implement.

I'm surprised.  Why is that?

> I'll think about it.

Thank you.



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

* Re: /* */ style comments in C++ sources
  2017-05-23 18:57 /* */ style comments in C++ sources Eli Zaretskii
  2017-05-23 20:31 ` Alan Mackenzie
@ 2017-05-24  9:08 ` Dani Moncayo
  1 sibling, 0 replies; 29+ messages in thread
From: Dani Moncayo @ 2017-05-24  9:08 UTC (permalink / raw)
  To: Emacs development discussions

On Tue, May 23, 2017 at 8:57 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> Is there a way to tell Emacs to use the C-style comments in C++
> sources?  (I couldn't find that in the CC Mode manual.)

FWIW: Sometimes, I've missed the opposite, i.e. "//"-style comments on
C sources.

It'd be nice if this was configurable.

-- 
Dani Moncayo



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

* Re: /* */ style comments in C++ sources
  2017-05-23 20:31 ` Alan Mackenzie
  2017-05-24  0:02   ` Richard Stallman
  2017-05-24  2:27   ` Eli Zaretskii
@ 2017-05-24 17:19   ` John Mastro
  2017-05-24 18:10     ` Eli Zaretskii
  2 siblings, 1 reply; 29+ messages in thread
From: John Mastro @ 2017-05-24 17:19 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: Eli Zaretskii, emacs-devel

Alan Mackenzie <acm@muc.de> wrote:
>> Is there a way to tell Emacs to use the C-style comments in C++
>> sources?  (I couldn't find that in the CC Mode manual.)
>
> No, there is no (reasonable) way to tell CC Mode what style of comments
> one prefers.
>
> People have asked about this before.  It seems like it would be a useful
> facility to add.  Though it might take a surprisingly large amount of
> work to implement.

I'm probably missing something obvious, but I thought setting
`comment-start' and `comment-end' worked for this?

        John



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

* Re: /* */ style comments in C++ sources
  2017-05-24 17:19   ` John Mastro
@ 2017-05-24 18:10     ` Eli Zaretskii
  2017-05-25  1:49       ` Stefan Monnier
  0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2017-05-24 18:10 UTC (permalink / raw)
  To: John Mastro; +Cc: acm, emacs-devel

> From: John Mastro <john.b.mastro@gmail.com>
> Date: Wed, 24 May 2017 10:19:20 -0700
> Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel <emacs-devel@gnu.org>
> 
> Alan Mackenzie <acm@muc.de> wrote:
> > No, there is no (reasonable) way to tell CC Mode what style of comments
> > one prefers.
> >
> > People have asked about this before.  It seems like it would be a useful
> > facility to add.  Though it might take a surprisingly large amount of
> > work to implement.
> 
> I'm probably missing something obvious, but I thought setting
> `comment-start' and `comment-end' worked for this?

It's very inconvenient, for starters.  Using a supported language
feature shouldn't require the user to mess with tricky regexps, IMO.



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

* Re: /* */ style comments in C++ sources
  2017-05-24  0:02   ` Richard Stallman
@ 2017-05-24 20:36     ` Sam Steingold
  0 siblings, 0 replies; 29+ messages in thread
From: Sam Steingold @ 2017-05-24 20:36 UTC (permalink / raw)
  To: emacs-devel

> * Richard Stallman <ezf@tah.bet> [2017-05-23 20:02:10 -0400]:
>
> [[[ To any NSA and FBI agents reading my email: please consider    ]]]
> [[[ whether defending the US Constitution against all enemies,     ]]]
> [[[ foreign or domestic, requires you to follow Snowden's example. ]]]
>
>   > People have asked about this before.  It seems like it would be a useful
>   > facility to add.  Though it might take a surprisingly large amount of
>   > work to implement.
>
> If we had a user option to control it, you could specify that
> in the -*- line or the local variables list.

Or maybe set it based on file content: if the user did not customize the
variable and the file does not set it, check if the first 1kb(?) uses
exclusively (predominantly?) one style and not the other.

-- 
Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.1504
http://steingoldpsychology.com http://www.childpsy.net https://jihadwatch.org
http://camera.org http://mideasttruth.com http://www.dhimmitude.org
Winners never quit; quitters never win; idiots neither win nor quit.




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

* Re: /* */ style comments in C++ sources
  2017-05-24  2:27   ` Eli Zaretskii
@ 2017-05-24 20:53     ` Alan Mackenzie
  2017-05-25  1:51       ` Stefan Monnier
                         ` (2 more replies)
  0 siblings, 3 replies; 29+ messages in thread
From: Alan Mackenzie @ 2017-05-24 20:53 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Hello, Eli.

On Wed, May 24, 2017 at 05:27:54 +0300, Eli Zaretskii wrote:
> > Date: Tue, 23 May 2017 20:31:44 +0000
> > Cc: emacs-devel@gnu.org
> > From: Alan Mackenzie <acm@muc.de>

> > On Tue, May 23, 2017 at 21:57:17 +0300, Eli Zaretskii wrote:
> > > Is there a way to tell Emacs to use the C-style comments in C++
> > > sources?  (I couldn't find that in the CC Mode manual.)

> > No, there is no (reasonable) way to tell CC Mode what style of comments
> > one prefers.

> > People have asked about this before.  It seems like it would be a useful
> > facility to add.

> Indeed, it would.  The rationale for me is projects like GDB, which
> switched from C to C++, but still prefer C-style comments for some
> reason.  (Maybe GCC also prefers that, I don't know.)

OK.  Give me a little time, and it will be implemented.

> > Though it might take a surprisingly large amount of work to
> > implement.

> I'm surprised.  Why is that?

There are quite a few (CC Mode) "language variables" to do with comment
delimiters, which are set statically at build-time.  They will need to be
amended to be ordinary variables which can be set at run-time, or the
functions which use them will need to be enhanced to selected between two
pairs of comment delimiters at run-time, or whatever.

> > I'll think about it.

What do you think of the following:

(i) There would be a new "CC Mode minor mode" with an interactive
function called `c-toggle-comment-style', which would toggle a new buffer
local variable, c-comment-style.  This variable could be set in local
variables, or in .emacs in the same way as any other CC Mode buffer
setting.
(ii) `c-toggle-comment-style' would be bound to an unused CC Mode
binding, possibly C-c C-k.
(iii) I'm also thinking about putting it on C-c C-;, though terminal
keyboards tend not to have C-; (mine doesn't (yet)).
(iv) The major mode mode line entry, which currently looks something
like "C/l" would be amended to "C/*l" or "C//l", with the obvious meaning.
(v) The new buffer-local variable `c-comment-style' would influence all
standard Emacs commands which create comments.

?

> Thank you.

-- 
Alan Mackenzie (Nuremberg, Germany).



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

* Re: /* */ style comments in C++ sources
  2017-05-24 18:10     ` Eli Zaretskii
@ 2017-05-25  1:49       ` Stefan Monnier
  0 siblings, 0 replies; 29+ messages in thread
From: Stefan Monnier @ 2017-05-25  1:49 UTC (permalink / raw)
  To: emacs-devel

>> I'm probably missing something obvious, but I thought setting
>> `comment-start' and `comment-end' worked for this?
> It's very inconvenient, for starters.  Using a supported language
> feature shouldn't require the user to mess with tricky regexps, IMO.

These aren't regexps, they're plain strings.
The only problem with them is that you have to be careful to set them
together, and you need to know what to set comment-end to for
LF-terminated comments.


        Stefan




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

* Re: /* */ style comments in C++ sources
  2017-05-24 20:53     ` Alan Mackenzie
@ 2017-05-25  1:51       ` Stefan Monnier
  2017-05-25  2:32       ` Eli Zaretskii
  2017-05-25  3:13       ` Herring, Davis
  2 siblings, 0 replies; 29+ messages in thread
From: Stefan Monnier @ 2017-05-25  1:51 UTC (permalink / raw)
  To: emacs-devel

> OK.  Give me a little time, and it will be implemented.

Bonus points if the same mechanism can be used in js-mode, pascal-mode,
etc...


        Stefan




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

* Re: /* */ style comments in C++ sources
  2017-05-24 20:53     ` Alan Mackenzie
  2017-05-25  1:51       ` Stefan Monnier
@ 2017-05-25  2:32       ` Eli Zaretskii
  2017-05-25 15:48         ` Alan Mackenzie
  2017-05-25  3:13       ` Herring, Davis
  2 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2017-05-25  2:32 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: emacs-devel

> Date: Wed, 24 May 2017 20:53:16 +0000
> Cc: emacs-devel@gnu.org
> From: Alan Mackenzie <acm@muc.de>
> 
> What do you think of the following:
> 
> (i) There would be a new "CC Mode minor mode" with an interactive
> function called `c-toggle-comment-style', which would toggle a new buffer
> local variable, c-comment-style.  This variable could be set in local
> variables, or in .emacs in the same way as any other CC Mode buffer
> setting.
> (ii) `c-toggle-comment-style' would be bound to an unused CC Mode
> binding, possibly C-c C-k.
> (iii) I'm also thinking about putting it on C-c C-;, though terminal
> keyboards tend not to have C-; (mine doesn't (yet)).
> (iv) The major mode mode line entry, which currently looks something
> like "C/l" would be amended to "C/*l" or "C//l", with the obvious meaning.
> (v) The new buffer-local variable `c-comment-style' would influence all
> standard Emacs commands which create comments.
> 
> ?

Sounds good to me, thanks.



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

* Re: /* */ style comments in C++ sources
  2017-05-24 20:53     ` Alan Mackenzie
  2017-05-25  1:51       ` Stefan Monnier
  2017-05-25  2:32       ` Eli Zaretskii
@ 2017-05-25  3:13       ` Herring, Davis
  2017-05-25 16:00         ` Alan Mackenzie
  2 siblings, 1 reply; 29+ messages in thread
From: Herring, Davis @ 2017-05-25  3:13 UTC (permalink / raw)
  To: Alan Mackenzie, Eli Zaretskii; +Cc: emacs-devel@gnu.org

> (i) There would be a new "CC Mode minor mode" with an interactive

Perhaps I'm missing the obvious: why a minor mode, and one with so generic a name?

Davis


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

* Re: /* */ style comments in C++ sources
  2017-05-25  2:32       ` Eli Zaretskii
@ 2017-05-25 15:48         ` Alan Mackenzie
  2017-05-25 16:59           ` Stefan Monnier
  2017-05-26  9:16           ` Alan Mackenzie
  0 siblings, 2 replies; 29+ messages in thread
From: Alan Mackenzie @ 2017-05-25 15:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Dani Moncayo, emacs-devel

On Thu, May 25, 2017 at 05:32:48 +0300, Eli Zaretskii wrote:
> > Date: Wed, 24 May 2017 20:53:16 +0000
> > Cc: emacs-devel@gnu.org
> > From: Alan Mackenzie <acm@muc.de>

> > What do you think of the following:

> > (i) There would be a new "CC Mode minor mode" with an interactive
> > function called `c-toggle-comment-style', which would toggle a new buffer
> > local variable, c-comment-style.  This variable could be set in local
> > variables, or in .emacs in the same way as any other CC Mode buffer
> > setting.
> > (ii) `c-toggle-comment-style' would be bound to an unused CC Mode
> > binding, possibly C-c C-k.
> > (iii) I'm also thinking about putting it on C-c C-;, though terminal
> > keyboards tend not to have C-; (mine doesn't (yet)).
> > (iv) The major mode mode line entry, which currently looks something
> > like "C/l" would be amended to "C/*l" or "C//l", with the obvious meaning.
> > (v) The new buffer-local variable `c-comment-style' would influence all
> > standard Emacs commands which create comments.

> > ?

> Sounds good to me, thanks.

OK, here's a first draught.  I've written some documentation for
cc-mode.texi, but I'm not happy about its state at the moment.

Basically, in a CC Mode buffer, C-c C-k will toggle the comment style.
Set `c-block-comment-flag' to nil or t in, e.g., a mode hook to do the
obvious.

I recommend starting a fresh Emacs with this patch, otherwise the
keymaps, which are defvars, wouldn't get reinitialised on loading the
patched CC Mode.  Etc.  As well as the three patched files, please also
recompile cc-engine.el (or, just recompile CC Mode as a whole).

Comments?



diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index a5ddcb4b92..582587a273 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -252,7 +252,8 @@ c-syntactic-information-on-region
 \f
 ;; Minor mode functions.
 (defun c-update-modeline ()
-  (let ((fmt (format "/%s%s%s%s"
+  (let ((fmt (format "/%s%s%s%s%s"
+		     (if c-block-comment-flag "*" "/")
 		     (if c-electric-flag "l" "")
 		     (if (and c-electric-flag c-auto-newline)
 			 "a" "")
@@ -270,9 +271,6 @@ c-update-modeline
 	(bare-mode-name (if (string-match "\\(^[^/]*\\)/" mode-name)
 			    (match-string 1 mode-name)
 			  mode-name)))
-;;     (setq c-submode-indicators
-;; 	  (if (> (length fmt) 1)
-;; 	      fmt))
     (setq mode-name
 	  (if (> (length fmt) 1)
 	      (concat bare-mode-name fmt)
@@ -362,6 +360,37 @@ c-toggle-electric-state
     (electric-indent-local-mode (if c-electric-flag 1 0)))
   (c-keep-region-active))
 
+;; `c-block-comment-flag' gets initialized to the current mode's default in
+;; c-basic-common-init.
+(defvar c-block-comment-flag nil)
+(make-variable-buffer-local 'c-block-comment-flag)
+
+(defun c-toggle-comment-style (&optional arg)
+  "Toggle the comment style between block and line comments.
+Optional numeric ARG, if supplied, switches to block comment
+style when positive, to line comment style when negative, and
+just toggles it when zero or left out.
+
+This action does nothing when the mode only has one comment style."
+  (interactive "P")
+  (setq c-block-comment-flag
+	(cond
+	 ((and c-line-comment-starter c-block-comment-starter)
+	  (c-calculate-state arg c-block-comment-flag))
+	 (c-line-comment-starter nil)
+	 (t t)))
+  (setq comment-start
+	(concat (if c-block-comment-flag
+		    c-block-comment-starter
+		  c-line-comment-starter)
+		" "))
+  (setq comment-end
+	(if c-block-comment-flag
+	    (concat " " c-block-comment-ender)
+	  ""))
+  (c-update-modeline)
+  (c-keep-region-active))
+
 \f
 ;; Electric keys
 
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 84d4eab75a..a9d5ac34ad 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -1449,6 +1449,7 @@ 'c-opt-op-identitier-prefix
 properly."
   t    "/*"
   awk  nil)
+(c-lang-defvar c-block-comment-starter (c-lang-const c-block-comment-starter))
 
 (c-lang-defconst c-block-comment-ender
   "String that ends block comments, or nil if such don't exist.
@@ -1458,6 +1459,7 @@ 'c-opt-op-identitier-prefix
 properly."
   t    "*/"
   awk  nil)
+(c-lang-defvar c-block-comment-ender (c-lang-const c-block-comment-ender))
 
 (c-lang-defconst c-block-comment-ender-regexp
   ;; Regexp which matches the end of a block comment (if such exists in the
@@ -1515,27 +1517,30 @@ 'c-opt-op-identitier-prefix
 (c-lang-defvar c-doc-comment-start-regexp
   (c-lang-const c-doc-comment-start-regexp))
 
+(c-lang-defconst c-block-comment-is-default
+  "Non-nil when the default comment style is block comment."
+  ;; Note to maintainers of derived modes: You are responsible for ensuring
+  ;; the pertinent `c-block-comment-{starter,ender}' or
+  ;; `c-line-comment-{starter,ender}' are non-nil.
+  t nil
+  c t)
+(c-lang-defvar c-block-comment-is-default
+  (c-lang-const c-block-comment-is-default))
+
 (c-lang-defconst comment-start
   "String that starts comments inserted with M-; etc.
 `comment-start' is initialized from this."
-  ;; Default: Prefer line comments to block comments, and pad with a space.
-  t (concat (or (c-lang-const c-line-comment-starter)
-		(c-lang-const c-block-comment-starter))
-	    " ")
-  ;; In C we still default to the block comment style since line
-  ;; comments aren't entirely portable.
-  c "/* ")
+  t (concat
+     (if (c-lang-const c-block-comment-is-default)
+	 (c-lang-const c-block-comment-starter)
+       (c-lang-const c-line-comment-starter))
+     " "))
 (c-lang-setvar comment-start (c-lang-const comment-start))
 
 (c-lang-defconst comment-end
   "String that ends comments inserted with M-; etc.
 `comment-end' is initialized from this."
-  ;; Default: Use block comment style if comment-start uses block
-  ;; comments, and pad with a space in that case.
-  t (if (string-match (concat "\\`\\("
-			      (c-lang-const c-block-comment-start-regexp)
-			      "\\)")
-		      (c-lang-const comment-start))
+  t (if (c-lang-const c-block-comment-is-default)
 	(concat " " (c-lang-const c-block-comment-ender))
       ""))
 (c-lang-setvar comment-end (c-lang-const comment-end))
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 20c63d4dbe..42c75461df 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -398,7 +398,7 @@ c-bind-special-erase-keys
   ;;(define-key c-mode-base-map "\C-c\C-v"  'c-version)
   ;; (define-key c-mode-base-map "\C-c\C-y"  'c-toggle-hungry-state)  Commented out by ACM, 2005-11-22.
   (define-key c-mode-base-map "\C-c\C-w" 'c-subword-mode)
-  )
+  (define-key c-mode-base-map "\C-c\C-k" 'c-toggle-comment-style))
 
 ;; We don't require the outline package, but we configure it a bit anyway.
 (cc-bytecomp-defvar outline-level)
@@ -547,7 +547,7 @@ c-basic-common-init
 	(setq yank-handled-properties (remq yank-cat-handler
 					    yank-handled-properties)))))
 
-  ;; For the benefit of adaptive file, which otherwise mis-fills.
+  ;; For the benefit of adaptive fill, which otherwise mis-fills.
   (setq fill-paragraph-handle-comment nil)
 
   ;; Install `c-fill-paragraph' on `fill-paragraph-function' so that a
@@ -623,6 +623,8 @@ c-basic-common-init
 
   ;; setup the comment indent variable in a Emacs version portable way
   (set (make-local-variable 'comment-indent-function) 'c-comment-indent)
+  ;; What sort of comments are default for M-;?
+  (setq c-block-comment-flag c-block-comment-is-default)
 
   ;; In Emacs 24.4 onwards, prevent Emacs's built in electric indentation from
   ;; messing up CC Mode's, and set `c-electric-flag' if `electric-indent-mode'


-- 
Alan Mackenzie (Nuremberg, Germany).



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

* Re: /* */ style comments in C++ sources
  2017-05-25  3:13       ` Herring, Davis
@ 2017-05-25 16:00         ` Alan Mackenzie
  0 siblings, 0 replies; 29+ messages in thread
From: Alan Mackenzie @ 2017-05-25 16:00 UTC (permalink / raw)
  To: Herring, Davis; +Cc: Eli Zaretskii, emacs-devel@gnu.org

Hello, Davis.

On Thu, May 25, 2017 at 03:13:36 +0000, Herring, Davis wrote:
> > (i) There would be a new "CC Mode minor mode" with an interactive

> Perhaps I'm missing the obvious: why a minor mode, and one with so generic a name?

That's "minor mode" in quote marks.  CC Mode has what its manual calls
"minor-mode-like features", such as electric indentation, which it
displays in the mode line (that's the "l" in "C/l") and which mostly
have C-c C-<letter> bindings to toggle them with.

That's the UI I've implemented this comment style switching with.  I'm
still working on the documentation for it, but "comment style" is
probably what I'll be calling it there.

> Davis

-- 
Alan Mackenzie (Nuremberg, Germany).



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

* Re: /* */ style comments in C++ sources
  2017-05-25 15:48         ` Alan Mackenzie
@ 2017-05-25 16:59           ` Stefan Monnier
  2017-05-25 17:44             ` Alan Mackenzie
  2017-05-26  9:16           ` Alan Mackenzie
  1 sibling, 1 reply; 29+ messages in thread
From: Stefan Monnier @ 2017-05-25 16:59 UTC (permalink / raw)
  To: emacs-devel

> OK, here's a first draught.  I've written some documentation for
> cc-mode.texi, but I'm not happy about its state at the moment.

But that doesn't help asm-mode, haskell-mode, js-mode, pascal-mode,
.... solve that same problem ;-(


        Stefan




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

* Re: /* */ style comments in C++ sources
  2017-05-25 16:59           ` Stefan Monnier
@ 2017-05-25 17:44             ` Alan Mackenzie
  0 siblings, 0 replies; 29+ messages in thread
From: Alan Mackenzie @ 2017-05-25 17:44 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Hello, Stefan.

On Thu, May 25, 2017 at 12:59:19 -0400, Stefan Monnier wrote:
> > OK, here's a first draught.  I've written some documentation for
> > cc-mode.texi, but I'm not happy about its state at the moment.

> But that doesn't help asm-mode, haskell-mode, js-mode, pascal-mode,
> .... solve that same problem ;-(

Hey, don't be like that!

It's a relatively small patch (a little over 150 lines) which doesn't
disrupt the smooth running of the mode.

Any of these other modes could take ideas from this patch, though there
is nothing profound or original in it.

Perhaps you could outline in some detail how your proposed universal
solution might work.  How big would it be?  How would it fit into CC
Mode and those other modes?

>         Stefan

-- 
Alan Mackenzie (Nuremberg, Germany).



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

* Re: /* */ style comments in C++ sources
  2017-05-25 15:48         ` Alan Mackenzie
  2017-05-25 16:59           ` Stefan Monnier
@ 2017-05-26  9:16           ` Alan Mackenzie
  2017-06-15 21:10             ` Alan Mackenzie
  1 sibling, 1 reply; 29+ messages in thread
From: Alan Mackenzie @ 2017-05-26  9:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel, Dani Moncayo

Hello, Eli.

On Thu, May 25, 2017 at 15:48:41 +0000, Alan Mackenzie wrote:

Sorry, I made a mistake in yesterday's post.  Instead of

> Basically, in a CC Mode buffer, C-c C-k will toggle the comment style.
> Set `c-block-comment-flag' to nil or t in, e.g., a mode hook to do the
> obvious.

, the second sentence of that paragraph should have read

  Call `c-toggle-comment-style' with a numeric argument in, e.g., a mode
  hook to do the obvious.

Merely setting `c-block-comment-flag' is insufficient to set Emacs's
comment variables.

-- 
Alan Mackenzie (Nuremberg, Germany).



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

* Re: /* */ style comments in C++ sources
  2017-05-26  9:16           ` Alan Mackenzie
@ 2017-06-15 21:10             ` Alan Mackenzie
  2017-06-16  6:22               ` Eli Zaretskii
  0 siblings, 1 reply; 29+ messages in thread
From: Alan Mackenzie @ 2017-06-15 21:10 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Dani Moncayo, emacs-devel

Hello, Eli.

On Fri, May 26, 2017 at 09:16:26 +0000, Alan Mackenzie wrote:
> On Thu, May 25, 2017 at 15:48:41 +0000, Alan Mackenzie wrote:

> Sorry, I made a mistake in yesterday's post.  Instead of

> > Basically, in a CC Mode buffer, C-c C-k will toggle the comment style.
> > Set `c-block-comment-flag' to nil or t in, e.g., a mode hook to do the
> > obvious.

> , the second sentence of that paragraph should have read

>   Call `c-toggle-comment-style' with a numeric argument in, e.g., a mode
>   hook to do the obvious.

More precisely, put

    (c-toggle-comment-style 1)

into your c++-mode-hook.

> Merely setting `c-block-comment-flag' is insufficient to set Emacs's
> comment variables.

There was no response to Stephan's suggestion (that the mechanism for
toggling comment style should somehow be shared by CC Mode, Pascal Mode,
Haskell Mode ....).  So I've just committed the amendment to master.

-- 
Alan Mackenzie (Nuremberg, Germany).



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

* Re: /* */ style comments in C++ sources
  2017-06-15 21:10             ` Alan Mackenzie
@ 2017-06-16  6:22               ` Eli Zaretskii
  2017-06-16 11:50                 ` Alan Mackenzie
  0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2017-06-16  6:22 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: dmoncayo, emacs-devel

> Date: Thu, 15 Jun 2017 21:10:07 +0000
> Cc: emacs-devel@gnu.org, Dani Moncayo <dmoncayo@gmail.com>
> From: Alan Mackenzie <acm@muc.de>
> 
> >   Call `c-toggle-comment-style' with a numeric argument in, e.g., a mode
> >   hook to do the obvious.
> 
> More precisely, put
> 
>     (c-toggle-comment-style 1)
> 
> into your c++-mode-hook.

Is this supposed to work in directory-local variables loaded via
.dir-locals.el?  If so, could older versions of Emacs barf when they
see this?

The reason I'm asking is that I'd like to add this to the
.dir-locals.el file in the GDB repository.

> There was no response to Stephan's suggestion (that the mechanism for
> toggling comment style should somehow be shared by CC Mode, Pascal Mode,
> Haskell Mode ....).  So I've just committed the amendment to master.

Thanks.



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

* Re: /* */ style comments in C++ sources
  2017-06-16  6:22               ` Eli Zaretskii
@ 2017-06-16 11:50                 ` Alan Mackenzie
  2017-06-16 12:40                   ` Alan Mackenzie
  2017-06-16 13:22                   ` Eli Zaretskii
  0 siblings, 2 replies; 29+ messages in thread
From: Alan Mackenzie @ 2017-06-16 11:50 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: dmoncayo, emacs-devel

Hello, Eli.

On Fri, Jun 16, 2017 at 09:22:06 +0300, Eli Zaretskii wrote:
> > Date: Thu, 15 Jun 2017 21:10:07 +0000
> > Cc: emacs-devel@gnu.org, Dani Moncayo <dmoncayo@gmail.com>
> > From: Alan Mackenzie <acm@muc.de>

> > >   Call `c-toggle-comment-style' with a numeric argument in, e.g., a mode
> > >   hook to do the obvious.

> > More precisely, put

> >     (c-toggle-comment-style 1)

> > into your c++-mode-hook.

> Is this supposed to work in directory-local variables loaded via
> .dir-locals.el?  If so, could older versions of Emacs barf when they
> see this?

Ah.  That's a problem.  Older versions of Emacs would indeed foul up on
seeing that in .dir-locals.el.

> The reason I'm asking is that I'd like to add this to the
> .dir-locals.el file in the GDB repository.

We could really do with being able to write (if (fboundp ...) ...) in a
.dir-locals.el.  I don't think we've any way of doing this at the moment.

Maybe I could amend the amendment for /* */ so that it would need only to
set a variable in .dir-locals.el rather than calling a function.  Would
that work better?

[ .... ]

> Thanks.

-- 
Alan Mackenzie (Nuremberg, Germany).



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

* Re: /* */ style comments in C++ sources
  2017-06-16 11:50                 ` Alan Mackenzie
@ 2017-06-16 12:40                   ` Alan Mackenzie
  2017-06-16 13:33                     ` Eli Zaretskii
  2017-06-16 13:22                   ` Eli Zaretskii
  1 sibling, 1 reply; 29+ messages in thread
From: Alan Mackenzie @ 2017-06-16 12:40 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel, dmoncayo

Hello again, Eli.

On Fri, Jun 16, 2017 at 11:50:13 +0000, Alan Mackenzie wrote:
> On Fri, Jun 16, 2017 at 09:22:06 +0300, Eli Zaretskii wrote:
> > > Date: Thu, 15 Jun 2017 21:10:07 +0000
> > > Cc: emacs-devel@gnu.org, Dani Moncayo <dmoncayo@gmail.com>
> > > From: Alan Mackenzie <acm@muc.de>

> > > >   Call `c-toggle-comment-style' with a numeric argument in, e.g., a mode
> > > >   hook to do the obvious.

> > > More precisely, put

> > >     (c-toggle-comment-style 1)

> > > into your c++-mode-hook.

> > Is this supposed to work in directory-local variables loaded via
> > .dir-locals.el?  If so, could older versions of Emacs barf when they
> > see this?

> Ah.  That's a problem.  Older versions of Emacs would indeed foul up on
> seeing that in .dir-locals.el.

> > The reason I'm asking is that I'd like to add this to the
> > .dir-locals.el file in the GDB repository.

> We could really do with being able to write (if (fboundp ...) ...) in a
> .dir-locals.el.  I don't think we've any way of doing this at the moment.

How about something like:

    (c++-mode . ((eval . (when (fboundp 'c-toggle-comment-style)
                           (c-toggle-comment-style 1)))))

(not tested)?  It might not be pretty, but it should surely work without
throwing errors in Emacs <= 25.2.

> Maybe I could amend the amendment for /* */ so that it would need only to
> set a variable in .dir-locals.el rather than calling a function.  Would
> that work better?

> [ .... ]

> > Thanks.

-- 
Alan Mackenzie (Nuremberg, Germany).



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

* Re: /* */ style comments in C++ sources
  2017-06-16 11:50                 ` Alan Mackenzie
  2017-06-16 12:40                   ` Alan Mackenzie
@ 2017-06-16 13:22                   ` Eli Zaretskii
  2017-06-16 13:37                     ` Stefan Monnier
  1 sibling, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2017-06-16 13:22 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: dmoncayo, emacs-devel

> Date: Fri, 16 Jun 2017 11:50:13 +0000
> Cc: emacs-devel@gnu.org, dmoncayo@gmail.com
> From: Alan Mackenzie <acm@muc.de>
> 
> > The reason I'm asking is that I'd like to add this to the
> > .dir-locals.el file in the GDB repository.
> 
> We could really do with being able to write (if (fboundp ...) ...) in a
> .dir-locals.el.  I don't think we've any way of doing this at the moment.

That's what I thought.  But doesn't 'eval' work?

> Maybe I could amend the amendment for /* */ so that it would need only to
> set a variable in .dir-locals.el rather than calling a function.  Would
> that work better?

Yes, setting a variable is better, since older Emacsen will just set a
variable which no code references.

Thanks.



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

* Re: /* */ style comments in C++ sources
  2017-06-16 12:40                   ` Alan Mackenzie
@ 2017-06-16 13:33                     ` Eli Zaretskii
  0 siblings, 0 replies; 29+ messages in thread
From: Eli Zaretskii @ 2017-06-16 13:33 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: emacs-devel, dmoncayo

> Date: Fri, 16 Jun 2017 12:40:10 +0000
> Cc: dmoncayo@gmail.com, emacs-devel@gnu.org
> From: Alan Mackenzie <acm@muc.de>
> 
> How about something like:
> 
>     (c++-mode . ((eval . (when (fboundp 'c-toggle-comment-style)
>                            (c-toggle-comment-style 1)))))
> 
> (not tested)?  It might not be pretty, but it should surely work without
> throwing errors in Emacs <= 25.2.

This works, thanks.  (It has the downside that it uses 'eval', which
by default asks for confirmation.  Bug GDB's .dir-locals.el already
uses 'eval' for a different purpose, and I have enable-local-eval set
to t in my .emacs.)



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

* Re: /* */ style comments in C++ sources
  2017-06-16 13:22                   ` Eli Zaretskii
@ 2017-06-16 13:37                     ` Stefan Monnier
  2017-06-16 14:25                       ` Stefan Monnier
  0 siblings, 1 reply; 29+ messages in thread
From: Stefan Monnier @ 2017-06-16 13:37 UTC (permalink / raw)
  To: emacs-devel

>> Maybe I could amend the amendment for /* */ so that it would need only to
>> set a variable in .dir-locals.el rather than calling a function.  Would
>> that work better?
> Yes, setting a variable is better, since older Emacsen will just set a
> variable which no code references.

You can set `comment-start` and `comment-end` already just fine, and that
will work with any old Emacs that supports .dir-locals.el (and not just
for CC-modes).


        Stefan




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

* Re: /* */ style comments in C++ sources
  2017-06-16 13:37                     ` Stefan Monnier
@ 2017-06-16 14:25                       ` Stefan Monnier
  2017-06-16 16:15                         ` Eli Zaretskii
  0 siblings, 1 reply; 29+ messages in thread
From: Stefan Monnier @ 2017-06-16 14:25 UTC (permalink / raw)
  To: emacs-devel

> You can set `comment-start` and `comment-end` already just fine, and that
> will work with any old Emacs that supports .dir-locals.el (and not just
> for CC-modes).

We could probably improve on this fairly easily by adding
a comment-end-alist so that the user only needs to set comment-start and
the matching comment-end would automatically be chosen.


        Stefan




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

* Re: /* */ style comments in C++ sources
  2017-06-16 14:25                       ` Stefan Monnier
@ 2017-06-16 16:15                         ` Eli Zaretskii
  2017-06-16 18:45                           ` Stefan Monnier
  0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2017-06-16 16:15 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Fri, 16 Jun 2017 10:25:47 -0400
> 
> > You can set `comment-start` and `comment-end` already just fine, and that
> > will work with any old Emacs that supports .dir-locals.el (and not just
> > for CC-modes).
> 
> We could probably improve on this fairly easily by adding
> a comment-end-alist so that the user only needs to set comment-start and
> the matching comment-end would automatically be chosen.

I thought back when you first suggested this, and I still think now
that letting users futz with these variables is not TRT.  We need a
command or a defcustom, which will do whatever is needed, including
setting these variables.



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

* Re: /* */ style comments in C++ sources
  2017-06-16 16:15                         ` Eli Zaretskii
@ 2017-06-16 18:45                           ` Stefan Monnier
  2017-06-16 19:30                             ` Eli Zaretskii
  0 siblings, 1 reply; 29+ messages in thread
From: Stefan Monnier @ 2017-06-16 18:45 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

>> We could probably improve on this fairly easily by adding
>> a comment-end-alist so that the user only needs to set comment-start and
>> the matching comment-end would automatically be chosen.
> I thought back when you first suggested this, and I still think now
> that letting users futz with these variables is not TRT.

It's always been meant to be modifiable by users (to change the default
comment markers, or to change the default spacing used for those comment
markers, ...).
The major mode just sets comment-start and comment-end to sane
default values.

Maybe you're thinking of comment-start-skip and comment-end-skip which
are variables which are supposed to reflect the language's syntax and
not the user's preference: these aren't expected to be modified by the
user, indeed.

> We need a command or a defcustom,

Defcustoms are global, so how do you suggest to let users specify these
choices per-mode?  Make it an alist?  Have each major mode invent its
own defcustom?

As for a command, we can easily write a command which gives a simple UI
on top of comment-end-alist, with completion, and defaulting to cycles
through the various alternatives.


        Stefan



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

* Re: /* */ style comments in C++ sources
  2017-06-16 18:45                           ` Stefan Monnier
@ 2017-06-16 19:30                             ` Eli Zaretskii
  0 siblings, 0 replies; 29+ messages in thread
From: Eli Zaretskii @ 2017-06-16 19:30 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

> From: Stefan Monnier <monnier@IRO.UMontreal.CA>
> Cc: emacs-devel@gnu.org
> Date: Fri, 16 Jun 2017 14:45:23 -0400
> 
> > We need a command or a defcustom,
> 
> Defcustoms are global, so how do you suggest to let users specify these
> choices per-mode?  Make it an alist?  Have each major mode invent its
> own defcustom?

I was thinking about a CC Mode specific defcustom.

> As for a command, we can easily write a command which gives a simple UI
> on top of comment-end-alist, with completion, and defaulting to cycles
> through the various alternatives.

That'd be fine with me.



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

end of thread, other threads:[~2017-06-16 19:30 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-23 18:57 /* */ style comments in C++ sources Eli Zaretskii
2017-05-23 20:31 ` Alan Mackenzie
2017-05-24  0:02   ` Richard Stallman
2017-05-24 20:36     ` Sam Steingold
2017-05-24  2:27   ` Eli Zaretskii
2017-05-24 20:53     ` Alan Mackenzie
2017-05-25  1:51       ` Stefan Monnier
2017-05-25  2:32       ` Eli Zaretskii
2017-05-25 15:48         ` Alan Mackenzie
2017-05-25 16:59           ` Stefan Monnier
2017-05-25 17:44             ` Alan Mackenzie
2017-05-26  9:16           ` Alan Mackenzie
2017-06-15 21:10             ` Alan Mackenzie
2017-06-16  6:22               ` Eli Zaretskii
2017-06-16 11:50                 ` Alan Mackenzie
2017-06-16 12:40                   ` Alan Mackenzie
2017-06-16 13:33                     ` Eli Zaretskii
2017-06-16 13:22                   ` Eli Zaretskii
2017-06-16 13:37                     ` Stefan Monnier
2017-06-16 14:25                       ` Stefan Monnier
2017-06-16 16:15                         ` Eli Zaretskii
2017-06-16 18:45                           ` Stefan Monnier
2017-06-16 19:30                             ` Eli Zaretskii
2017-05-25  3:13       ` Herring, Davis
2017-05-25 16:00         ` Alan Mackenzie
2017-05-24 17:19   ` John Mastro
2017-05-24 18:10     ` Eli Zaretskii
2017-05-25  1:49       ` Stefan Monnier
2017-05-24  9:08 ` Dani Moncayo

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).