🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #88048

[19.25.92] kill-comment -- awkward binding, suggestion

#88048
From: Erik Naggum
Date: Fri, 05 Aug 1994 23:26
201 lines
9379 bytes
In GNU Emacs 19.25.92.4 (sparc-sun-sunos4shr) of Thu Aug  4 1994 on naggum.no

`kill-comment' is currently reached with C-u - C-x ; , which may be a good
idea if you want to discourage people from killing comments, but when you
need it, it's kind of painful.  more importantly, I don't think it's very
intuitive that setting the comment column and killing comments should be
opposites, as it were, through the negative prefix.  I think it would be
much more intuitive for `indent-for-comment' to interpret the negative
prefix to mean kill-comment.

here's a patch to implement the suggestion, complete with info patches.
(the old binding is still available.)  the changes to the lisp code are
much smaller than they appear because of the indentation cause by the
addition of

  (if (eq arg '-)
      (kill-comment nil)

and its closing paren.

best regards,
</Erik>

---------------------------------------------------------------------------

Fri Aug  5 12:18:18 1994  Erik Naggum  <erik@naggum.no>

	* simple.el (indent-for-comment): just minus as arg means kill
	any comment on this line, like `set-comment-column'.

*** lisp/simple.el.~1~	Fri Jul 29 21:27:34 1994
--- lisp/simple.el	Fri Aug  5 12:08:26 1994
***************
*** 1864,1910 ****
  This function is called with no args with point at the beginning of
  the comment's starting delimiter.")

! (defun indent-for-comment ()
!   "Indent this line's comment to comment column, or insert an empty comment."
!   (interactive "*")
!   (beginning-of-line 1)
!   (if (null comment-start)
!       (error "No comment syntax defined")
!     (let* ((eolpos (save-excursion (end-of-line) (point)))
! 	   cpos indent begpos)
!       (if (re-search-forward comment-start-skip eolpos 'move)
! 	  (progn (setq cpos (point-marker))
! 		 ;; Find the start of the comment delimiter.
! 		 ;; If there were paren-pairs in comment-start-skip,
! 		 ;; position at the end of the first pair.
! 		 (if (match-end 1)
! 		     (goto-char (match-end 1))
! 		   ;; If comment-start-skip matched a string with
! 		   ;; internal whitespace (not final whitespace) then
! 		   ;; the delimiter start at the end of that
! 		   ;; whitespace.  Otherwise, it starts at the
! 		   ;; beginning of what was matched.
! 		   (skip-syntax-backward " " (match-beginning 0))
! 		   (skip-syntax-backward "^ " (match-beginning 0)))))
!       (setq begpos (point))
!       ;; Compute desired indent.
!       (if (= (current-column)
! 	     (setq indent (if comment-indent-hook
! 			      (funcall comment-indent-hook)
! 			    (funcall comment-indent-function))))
! 	  (goto-char begpos)
! 	;; If that's different from current, change it.
! 	(skip-chars-backward " \t")
! 	(delete-region (point) begpos)
! 	(indent-to indent))
!       ;; An existing comment?
!       (if cpos
! 	  (progn (goto-char cpos)
! 		 (set-marker cpos nil))
! 	;; No, insert one.
! 	(insert comment-start)
! 	(save-excursion
! 	  (insert comment-end))))))

  (defun set-comment-column (arg)
    "Set the comment column based on point.
--- 1848,1897 ----
  This function is called with no args with point at the beginning of
  the comment's starting delimiter.")

! (defun indent-for-comment (&optional arg)
!   "Indent this line's comment to comment column, or insert an empty comment.
! With just minus as arg, kill any comment on this line."
!   (interactive "P")
!   (if (eq arg '-)
!       (kill-comment nil)
!     (beginning-of-line 1)
!     (if (null comment-start)
! 	(error "No comment syntax defined")
!       (let* ((eolpos (save-excursion (end-of-line) (point)))
! 	     cpos indent begpos)
! 	(if (re-search-forward comment-start-skip eolpos 'move)
! 	    (progn (setq cpos (point-marker))
! 		   ;; Find the start of the comment delimiter.
! 		   ;; If there were paren-pairs in comment-start-skip,
! 		   ;; position at the end of the first pair.
! 		   (if (match-end 1)
! 		       (goto-char (match-end 1))
! 		     ;; If comment-start-skip matched a string with
! 		     ;; internal whitespace (not final whitespace) then
! 		     ;; the delimiter start at the end of that
! 		     ;; whitespace.  Otherwise, it starts at the
! 		     ;; beginning of what was matched.
! 		     (skip-syntax-backward " " (match-beginning 0))
! 		     (skip-syntax-backward "^ " (match-beginning 0)))))
! 	(setq begpos (point))
! 	;; Compute desired indent.
! 	(if (= (current-column)
! 	       (setq indent (if comment-indent-hook
! 				(funcall comment-indent-hook)
! 			      (funcall comment-indent-function))))
! 	    (goto-char begpos)
! 	  ;; If that's different from current, change it.
! 	  (skip-chars-backward " \t")
! 	  (delete-region (point) begpos)
! 	  (indent-to indent))
! 	;; An existing comment?
! 	(if cpos
! 	    (progn (goto-char cpos)
! 		   (set-marker cpos nil))
! 	  ;; No, insert one.
! 	  (insert comment-start)
! 	  (save-excursion
! 	    (insert comment-end)))))))

  (defun set-comment-column (arg)
    "Set the comment column based on point.

*** man/programs.texi.~1~	Tue Aug  2 06:13:37 1994
--- man/programs.texi	Fri Aug  5 12:27:16 1994
***************
*** 767,773 ****
  Insert or align comment (@code{indent-for-comment}).
  @item C-x ;
  Set comment column (@code{set-comment-column}).
! @item C-u - C-x ;
  Kill comment on current line (@code{kill-comment}).
  @item M-@key{LFD}
  Like @key{RET} followed by inserting and aligning a comment
--- 767,773 ----
  Insert or align comment (@code{indent-for-comment}).
  @item C-x ;
  Set comment column (@code{set-comment-column}).
! @item C-u - M-;
  Kill comment on current line (@code{kill-comment}).
  @item M-@key{LFD}
  Like @key{RET} followed by inserting and aligning a comment
***************
*** 814,827 ****
    Even when an existing comment is properly aligned, @kbd{M-;} is still
  useful for moving directly to the start of the comment.

! @kindex C-u - C-x ;
  @findex kill-comment
!   @kbd{C-u - C-x ;} (@code{kill-comment}) kills the comment on the current line,
  if there is one.  The indentation before the start of the comment is killed
  as well.  If there does not appear to be a comment in the line, nothing is
  done.  To reinsert the comment on another line, move to the end of that
  line, do @kbd{C-y}, and then do @kbd{M-;} to realign it.  Note that
! @kbd{C-u - C-x ;} is not a distinct key; it is @kbd{C-x ;} (@code{set-comment-column})
  with a negative argument.  That command is programmed so that when it
  receives a negative argument it calls @code{kill-comment}.  However,
  @code{kill-comment} is a valid command which you could bind directly to a
--- 814,827 ----
    Even when an existing comment is properly aligned, @kbd{M-;} is still
  useful for moving directly to the start of the comment.

! @kindex C-u - M-;
  @findex kill-comment
!   @kbd{C-u - M-;} (@code{kill-comment}) kills the comment on the current line,
  if there is one.  The indentation before the start of the comment is killed
  as well.  If there does not appear to be a comment in the line, nothing is
  done.  To reinsert the comment on another line, move to the end of that
  line, do @kbd{C-y}, and then do @kbd{M-;} to realign it.  Note that
! @kbd{C-u - M-;} is not a distinct key; it is @kbd{M-;} (@code{indent-for-comment})
  with a negative argument.  That command is programmed so that when it
  receives a negative argument it calls @code{kill-comment}.  However,
  @code{kill-comment} is a valid command which you could bind directly to a
***************
*** 870,877 ****
  (@code{set-comment-column}) sets the comment column to the column point is
  at.  @kbd{C-u C-x ;} sets the comment column to match the last comment
  before point in the buffer, and then does a @kbd{M-;} to align the
! current line's comment under the previous one.  Note that @kbd{C-u - C-x ;}
! runs the function @code{kill-comment} as described above.

    The variable @code{comment-column} is per-buffer: setting the variable
  in the normal fashion affects only the current buffer, but there is a
--- 870,876 ----
  (@code{set-comment-column}) sets the comment column to the column point is
  at.  @kbd{C-u C-x ;} sets the comment column to match the last comment
  before point in the buffer, and then does a @kbd{M-;} to align the
! current line's comment under the previous one.

    The variable @code{comment-column} is per-buffer: setting the variable
  in the normal fashion affects only the current buffer, but there is a
Technical Details
Message-ID: <19940805.3983@naggum.no>
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!sun.cais.com!io.org!uunet.ca!uunet.ca!scipio.cyberstore.ca!vanbc.wimsey.com!deep.rsoft.bc.ca!agate!howland.reston.ans.net!math.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!naggum.no!erik

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,2d0654b2358ddc26,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1994-08-06 18:41:30 PST
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!sun.cais.com!io.org!uunet.ca!uunet.ca!scipio.cyberstore.ca!vanbc.wimsey.com!deep.rsoft.bc.ca!agate!howland.reston.ans.net!math.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!naggum.no!erik
From: erik@naggum.no (Erik Naggum)
Newsgroups: gnu.emacs.bug
Subject: [19.25.92] kill-comment -- awkward binding, suggestion
Date: 5 Aug 1994 19:26:55 -0400
Organization: Naggum Software; +47 2295 0313
Lines: 203
Sender: daemon@cis.ohio-state.edu
Approved: bug-gnu-emacs@prep.ai.mit.edu
Distribution: gnu
Message-ID: <19940805.3983@naggum.no>