🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #99560

Extension to C mode

#99560
From: Thomas Bellman
Date: Wed, 11 Jul 1990 09:24
95 lines
4488 bytes
I've always been annoyed by the way Emacs treats comments
standing last on a line in C mode when doing a 'indent-c-exp'.
When I have placed the comments where I want them, directly after
a closing brace, after a varaible declaration, et c, et c, and do
apply the indent-c-exp command to some portion of the code, all
those comments gets lined up at the comment-column column.  I
simply don't like that.  So, today I decided to do something
about it, and here's the result:

A new variable called 'c-dont-indent-trailing-comments' (lovely
name, don't you think? :-) tells what behaviour 'indent-c-exp'
has - default is nil, the old behaviour.  When non-nil, 'indent-
c-exp' doesn't touch comments that aren't alone on the line.

Well, enough said about this.  Here comes the context diff to
c-mode.el.  Share and enjoy!

--
Thomas Bellman,  Lysator Computer Club    ! "Make Love - Nich Wahr"
          Linkoping University, Sweden    ! "What sane person could live in
e-mail:         Bellman@Lysator.LiU.SE    !  this world and not be crazy?"
	  O /
Cut here --X---------------------------------------------------------------
	  O \

*** c-mode.el	Wed Jul 11 10:27:02 1990
--- new.c-mode.el	Wed Jul 11 10:21:41 1990
***************
*** 82,91 ****
--- 82,95 ----
  and after colons and semicolons, inserted in C code.")
  
  (defconst c-tab-always-indent t
    "*Non-nil means TAB in C mode should always reindent the current line,
  regardless of where in the line point is when the TAB command is used.")
+ (defconst c-dont-indent-trailing-comments nil
+   "*Non-nil means don't reindent comments following text (i e
+ doesn't stand alone on a line) when doing a indent-c-exp
+ (normally M-C-q).")
  
  (defun c-mode ()
    "Major mode for editing C code.
  Expression and list commands understand all C brackets.
  Tab indents for C code.
***************
*** 92,101 ****
--- 96,109 ----
  Comments are delimited with /* ... */.
  Paragraphs are separated by blank lines only.
  Delete converts tabs to spaces as it moves back.
  \\{c-mode-map}
  Variables controlling indentation style:
+  c-dont-indent-trailing-comments
+     Non-nil means don't reindent comments following text (i e
+     doesn't stand alone on a line) when doing a indent-c-exp
+     (normally M-C-q).
   c-tab-always-indent
      Non-nil means TAB in C mode should always reindent the current line,
      regardless of where in the line point is when the TAB command is used.
   c-auto-newline
      Non-nil means automatically newline before and after braces,
***************
*** 651,660 ****
  		(= (following-char) ?\#)
  		(progn
  		  (delete-region (point) (progn (beginning-of-line) (point)))
  		  (indent-to this-indent)))
  	    ;; Indent any comment following the text.
! 	    (or (looking-at comment-start-skip)
! 		(if (re-search-forward comment-start-skip (save-excursion (end-of-line) (point)) t)
! 		    (progn (indent-for-comment) (beginning-of-line)))))))))
  ; (message "Indenting C expression...done")
    )
--- 659,674 ----
  		(= (following-char) ?\#)
  		(progn
  		  (delete-region (point) (progn (beginning-of-line) (point)))
  		  (indent-to this-indent)))
  	    ;; Indent any comment following the text.
! 	    (if (not c-dont-indent-trailing-comments)
! 		(or (looking-at comment-start-skip)
! 		    (if (re-search-forward comment-start-skip
! 					   (save-excursion (end-of-line)
! 							   (point))
! 					   t)
! 			(progn
! 			  (indent-for-comment)
! 			  (beginning-of-line))))))))))
  ; (message "Indenting C expression...done")
    )
--
Thomas Bellman,  Lysator Computer Club    ! "Make Love - Nich Wahr"
          Linkoping University, Sweden    ! "What sane person could live in
e-mail:         Bellman@Lysator.LiU.SE    !  this world and not be crazy?"
Technical Details
Message-ID: <127@lysator.liu.se>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!sunic!liuida!isy!lysator.liu.se!bellman

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,f62e11e4637690c7,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1990-07-11 02:24:28 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!sunic!liuida!isy!lysator.liu.se!bellman
From: bellman@lysator.liu.se (Thomas Bellman)
Newsgroups: gnu.emacs.bug
Subject: Extension to C mode
Keywords: c-mode, comments, indentation
Message-ID: <127@lysator.liu.se>
Date: 11 Jul 90 09:24:28 GMT
Sender: news@isy.liu.se (Lord of the News)
Distribution: gnu
Organization: Lysator Computer Club, Linkoping University, Sweden
Lines: 95
Posted: Wed Jul 11 10:24:28 1990