all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* setting continuation chars
@ 2006-06-28 19:20 gamename
  2006-06-29  7:38 ` Mathias Dahl
  0 siblings, 1 reply; 5+ messages in thread
From: gamename @ 2006-06-28 19:20 UTC (permalink / raw)


Hi,

I have a tcl file that uses procedures with lots of parms.
Consequently, I often have to span multiple lines.
Example

blit -a <some parm> -b <some parm> -c <some parm> ...

To span multiple lines, you need to use the backslash ("\") as a
continuation.
Example:

blit \
-a <some parm> \
-b <some parm> \
-c <some parm>

But, I prefer a format where all the backslashes are placed in a
specific column.  It would then look more like this:

blit                  \
-a <some parm>        \
-b <some parm>        \
-c <some parm>

...which makes the continuations obvious.

Is there any way to do one of the following in emacs:

1) automagically put the continuation at a specific column number
OR
2) use some sort of command (regex?) to insert the needed spaces up to
a certain column and then put in a backslash?


TIA,
-T

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

* Re: setting continuation chars
  2006-06-28 19:20 setting continuation chars gamename
@ 2006-06-29  7:38 ` Mathias Dahl
  2006-06-29 11:24   ` gamename
  0 siblings, 1 reply; 5+ messages in thread
From: Mathias Dahl @ 2006-06-29  7:38 UTC (permalink / raw)


"gamename" <namesagame-usenet@yahoo.com> writes:

> 2) use some sort of command (regex?) to insert the needed spaces up to
> a certain column and then put in a backslash?

Or, maybe something like this:

(defun line-up-continuations ()
 "Line up all continuations from point and forward."
  (interactive)
  (save-excursion
    ;; Find backslash at the end of a line
    (while (search-forward-regexp "\\\\$" nil t)
      ;; Back up to set point before it
      (backward-char 1)
      ;; Indent to a fixed column
      (indent-to-column 40)
      ;; Step forward again, else the search will find
      ;; the same backslash again.
      (forward-char 1))))

Replace `40' with whatever column number you like.



Enjoy!

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

* Re: setting continuation chars
  2006-06-29  7:38 ` Mathias Dahl
@ 2006-06-29 11:24   ` gamename
  0 siblings, 0 replies; 5+ messages in thread
From: gamename @ 2006-06-29 11:24 UTC (permalink / raw)


Thanks Mathias!

-T

Mathias Dahl wrote:
> "gamename" <namesagame-usenet@yahoo.com> writes:
>
> > 2) use some sort of command (regex?) to insert the needed spaces up to
> > a certain column and then put in a backslash?
>
> Or, maybe something like this:
>
> (defun line-up-continuations ()
>  "Line up all continuations from point and forward."
>   (interactive)
>   (save-excursion
>     ;; Find backslash at the end of a line
>     (while (search-forward-regexp "\\\\$" nil t)
>       ;; Back up to set point before it
>       (backward-char 1)
>       ;; Indent to a fixed column
>       (indent-to-column 40)
>       ;; Step forward again, else the search will find
>       ;; the same backslash again.
>       (forward-char 1))))
>
> Replace `40' with whatever column number you like.
> 
> 
> 
> Enjoy!

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

* RE: setting continuation chars
@ 2006-06-29 20:35 Jay Bingham
  0 siblings, 0 replies; 5+ messages in thread
From: Jay Bingham @ 2006-06-29 20:35 UTC (permalink / raw)


> 2) use some sort of command (regex?) to insert the needed spaces up 
to
> a certain column and then put in a backslash?

You got my curiosity up.  So I went looking and found that there is a 
function called move-to-column that will move to the column given as 
an argument.  That inspired me to write a little package (see the 
text following my signature) that contains a function that will 
insert the line continuation character in a specified column when it 
is invoked.
The package assigns a key "C-return" to the function continue-line.

To use the package you just need to put it in a file called continue-
line.el and put that in your load path.  Everything else that you 
need to know should be contained in the comments and descriptions in 
the package.

__
J_)
C_)ingham


;;; continue-line.el --- continue a line based on the major mode

;;--------------------------------------------------------------------
--
-------
;; Last Modified Time-stamp: <29Jun2006 14:33:50 CDT by JCBingham>
;;--------------------------------------------------------------------
--
-------

;; Copyright (C) 2006 JCBingham
;;
;; Author: b.jc-emacs@netzero.com
;; Version: $Id: continue-line.el,v 0.01 2006/06/29 17:01:35 JCBingham
Exp $
;; Keywords: mode based line continuation
;; Requirements: Emacs-21.3 or higher
;; Status: not intended to be distributed yet
;; X-URL: not distributed yet

;; This program is free software; you can redistribute it and/or 
modify
;; it under the terms of the GNU General Public License as published 
by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


;;; Commentary:

;; This package provides the capability to continue a line based on 
the
major
;; mode with the line continuation character or characters in the same
column.
;;
;; The user configurable variables in this package are:
;;	cli-mode-continuation-str
;;	cli-targ
;;
;; The interactive functions in this package are:
;;	continue-line
;;
;; The keys defined in this package are:
;;	C-return set to continue-line

;; To load this package in all your emacs sessions put this file into
your
;; load-path and put the following line (without the comment 
delimiter)
;; into your ~/.emacs:
;;   (require 'continue-line)

;; To auto-load this package in your emacs sessions (loaded only when
needed)
;; put this file into your load-path and put the following lines
(without the
;; comment delimiters) into your ~/.emacs:
;;   (autoload ' continue-line "continue-line"
;;  "Continue a line based on the major mode that is active in the
buffer."
;;  t nil)
;;   (autoload ' set-continue-column "continue-line"
;;  "Set the continuation character column for the continue-line
function."
;;  t nil)


;;;++ Module History ++

;; 29 Jun 2006 - JCBingham -
;;	 Initial version containing the following -
;;	user configurable variables:
;;	 cli-mode-continuation-str
;;	 cli-targ
;;
;;	interactive functions:
;;	 continue-line
;;	 set-continue-column
;;
;;	keys defined:
;;	 C-return set to continue-line

;;;-- Module History end --


;;; Code:

(provide 'continue-line)



;;;;##################################################################
##
######
;;;;  Customizable Package Variables
;;;;##################################################################
##
######

;;;=======<Variable>=======<Variable>=======<Variable>=======<Variable
>=
======
(defvar cli-mode-continuation-str
      '((makefile-mode . "\\")
	(sh-mode . "\\")
	(tcl-mode . "\\"))
  "An a-list containing the continuation string for modes that use 
them.
Each element of the list is an associated pair of the mode name and 
the
string
that will be inserted by the continue-line function when that mode is
active.

The default values can be overridden by placing the sexp
\(setq cli-mode-continuation-str
      '\(\(makefile-mode . \"\\\\\"\)
	\(sh-mode . \"\\\\\"\)
	\(tcl-mode . \"\\\\\"\)\)
in your .emacs file and changing the backslashes to the desired
characters.
It should be noted that all of the emacs string constraints apply.
Hence to
insert a single backslash two are required.
After the package is loaded the list can be manipulated using any of 
the
elisp
list manipulation functions.  Adding an element to the front of the 
list
with
the same car as an element already in the list will cause later 
element
to be
superseded." )

(defvar cli-targ 79
  "The starting column for the line continuation string.
This is an integer variable specifying the column in which the
continue-line
function will begin inserting the line continuation string.
The value should be positive but is not required to be since the
function uses
the absolute value of the variable.
It is a buffer-local variable.

The default value can be overridden by placing the sexp
\(setq cli-targ nn\)
where nn is the desired column number in your .emacs file." )
(make-variable-buffer-local 'cli-targ)


;;;;##################################################################
##
######
;;;;  Interactive Functions
;;;;##################################################################
##
######

;;========<Function>=======<Function>=======<Function>=======<Function
>=
======
;; Function: continue-line
;;
;; Psuedo code:
;;  if no prefix argument was specified
;;  then set the target column to the default target value
;;  set the target column to the absolute value of itself
;;  if there is a continuation string defined for the mode
;;  then
;;    if the target column is greater than the current column
;;    then
;;      insert spaces/tabs until the cursor is in the specified column
;;    else
;;      insert a single space
;;    insert the continuation string
;;  insert a carriage return
;;  indent according to the major mode in effect
;;
(defun continue-line (&optional targ)
  "Continue a line based on the major mode that is active in the 
buffer.
 If there is a continuation string defined for the mode,
   insert spaces/tabs until the cursor is in the specified column
(unless the
     current column is at or beyond the target column, in which case
insert a
     single space)
   insert the continuation string.
 Insert a carriage return,
 indent according to the major mode in effect.
When invoked with a prefix argument the absolute value of the argument
is used
as the target column. When invoked without a prefix argument the 
target
column
is obtained from the variable cli-targ.  cli-targ is a buffer local
variable."
  (interactive "*P")
  (if (not targ) (setq targ cli-targ))
  (setq targ (abs targ))
  (when (cdr (assoc major-mode cli-mode-continuation-str))
    (if (> targ (current-column))
	(move-to-column targ t)
      (insert " "))
    (insert (cdr (assoc major-mode cli-mode-continuation-str))))
  (insert "\n")
  (indent-according-to-mode))

;;========<Function>=======<Function>=======<Function>=======<Function
>=
======
;; Function: set-continue-column
;;
;; Psuedo code:
;;  if the argument is greater than 0
;;  then
;;    set the default target value to the argument
;;  else
;;    issue an error message
;;    return nil
;;
(defun set-continue-column (val)
  "Set the continuation character column for the continue-line 
function.
The column number must be greater than 0."
  (interactive "p")
  (if (> val 0)
      (setq cli-targ val)
    (message "Argument greater than 0 is required")
    nil))

(global-set-key [C-return] 'continue-line)

;;; END OF continue-line.el




_____________________________________________________________________
PrivatePhone - FREE telephone number & voicemail.
A number so private, you can make it public.
http://www.privatephone.com


_____________________________________________________________________
PrivatePhone - FREE telephone number & voicemail.
A number so private, you can make it public.
http://www.privatephone.com

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

* Re: setting continuation chars
       [not found] <mailman.3529.1151613525.9609.help-gnu-emacs@gnu.org>
@ 2006-07-08  8:47 ` gamename
  0 siblings, 0 replies; 5+ messages in thread
From: gamename @ 2006-07-08  8:47 UTC (permalink / raw)


Thanks Jay!

-T


Jay Bingham wrote:
> > 2) use some sort of command (regex?) to insert the needed spaces up
> to
> > a certain column and then put in a backslash?
>
> You got my curiosity up.  So I went looking and found that there is a
> function called move-to-column that will move to the column given as
> an argument.  That inspired me to write a little package (see the
> text following my signature) that contains a function that will
> insert the line continuation character in a specified column when it
> is invoked.
> The package assigns a key "C-return" to the function continue-line.
>
> To use the package you just need to put it in a file called continue-
> line.el and put that in your load path.  Everything else that you
> need to know should be contained in the comments and descriptions in
> the package.
>
> __
> J_)
> C_)ingham
>
>
> ;;; continue-line.el --- continue a line based on the major mode
>
> ;;--------------------------------------------------------------------
> --
> -------
> ;; Last Modified Time-stamp: <29Jun2006 14:33:50 CDT by JCBingham>
> ;;--------------------------------------------------------------------
> --
> -------
>
> ;; Copyright (C) 2006 JCBingham
> ;;
> ;; Author: b.jc-emacs@netzero.com
> ;; Version: $Id: continue-line.el,v 0.01 2006/06/29 17:01:35 JCBingham
> Exp $
> ;; Keywords: mode based line continuation
> ;; Requirements: Emacs-21.3 or higher
> ;; Status: not intended to be distributed yet
> ;; X-URL: not distributed yet
>
> ;; This program is free software; you can redistribute it and/or
> modify
> ;; it under the terms of the GNU General Public License as published
> by
> ;; the Free Software Foundation; either version 2, or (at your option)
> ;; any later version.
> ;;
> ;; This program is distributed in the hope that it will be useful,
> ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
> ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> ;; GNU General Public License for more details.
> ;;
> ;; You should have received a copy of the GNU General Public License
> ;; along with this program; if not, write to the Free Software
> ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
>
>
> ;;; Commentary:
>
> ;; This package provides the capability to continue a line based on
> the
> major
> ;; mode with the line continuation character or characters in the same
> column.
> ;;
> ;; The user configurable variables in this package are:
> ;;	cli-mode-continuation-str
> ;;	cli-targ
> ;;
> ;; The interactive functions in this package are:
> ;;	continue-line
> ;;
> ;; The keys defined in this package are:
> ;;	C-return set to continue-line
>
> ;; To load this package in all your emacs sessions put this file into
> your
> ;; load-path and put the following line (without the comment
> delimiter)
> ;; into your ~/.emacs:
> ;;   (require 'continue-line)
>
> ;; To auto-load this package in your emacs sessions (loaded only when
> needed)
> ;; put this file into your load-path and put the following lines
> (without the
> ;; comment delimiters) into your ~/.emacs:
> ;;   (autoload ' continue-line "continue-line"
> ;;  "Continue a line based on the major mode that is active in the
> buffer."
> ;;  t nil)
> ;;   (autoload ' set-continue-column "continue-line"
> ;;  "Set the continuation character column for the continue-line
> function."
> ;;  t nil)
>
>
> ;;;++ Module History ++
>
> ;; 29 Jun 2006 - JCBingham -
> ;;	 Initial version containing the following -
> ;;	user configurable variables:
> ;;	 cli-mode-continuation-str
> ;;	 cli-targ
> ;;
> ;;	interactive functions:
> ;;	 continue-line
> ;;	 set-continue-column
> ;;
> ;;	keys defined:
> ;;	 C-return set to continue-line
>
> ;;;-- Module History end --
>
>
> ;;; Code:
>
> (provide 'continue-line)
>
>
>
> ;;;;##################################################################
> ##
> ######
> ;;;;  Customizable Package Variables
> ;;;;##################################################################
> ##
> ######
>
> ;;;=======<Variable>=======<Variable>=======<Variable>=======<Variable
> >=
> ======
> (defvar cli-mode-continuation-str
>       '((makefile-mode . "\\")
> 	(sh-mode . "\\")
> 	(tcl-mode . "\\"))
>   "An a-list containing the continuation string for modes that use
> them.
> Each element of the list is an associated pair of the mode name and
> the
> string
> that will be inserted by the continue-line function when that mode is
> active.
>
> The default values can be overridden by placing the sexp
> \(setq cli-mode-continuation-str
>       '\(\(makefile-mode . \"\\\\\"\)
> 	\(sh-mode . \"\\\\\"\)
> 	\(tcl-mode . \"\\\\\"\)\)
> in your .emacs file and changing the backslashes to the desired
> characters.
> It should be noted that all of the emacs string constraints apply.
> Hence to
> insert a single backslash two are required.
> After the package is loaded the list can be manipulated using any of
> the
> elisp
> list manipulation functions.  Adding an element to the front of the
> list
> with
> the same car as an element already in the list will cause later
> element
> to be
> superseded." )
>
> (defvar cli-targ 79
>   "The starting column for the line continuation string.
> This is an integer variable specifying the column in which the
> continue-line
> function will begin inserting the line continuation string.
> The value should be positive but is not required to be since the
> function uses
> the absolute value of the variable.
> It is a buffer-local variable.
>
> The default value can be overridden by placing the sexp
> \(setq cli-targ nn\)
> where nn is the desired column number in your .emacs file." )
> (make-variable-buffer-local 'cli-targ)
>
>
> ;;;;##################################################################
> ##
> ######
> ;;;;  Interactive Functions
> ;;;;##################################################################
> ##
> ######
>
> ;;========<Function>=======<Function>=======<Function>=======<Function
> >=
> ======
> ;; Function: continue-line
> ;;
> ;; Psuedo code:
> ;;  if no prefix argument was specified
> ;;  then set the target column to the default target value
> ;;  set the target column to the absolute value of itself
> ;;  if there is a continuation string defined for the mode
> ;;  then
> ;;    if the target column is greater than the current column
> ;;    then
> ;;      insert spaces/tabs until the cursor is in the specified column
> ;;    else
> ;;      insert a single space
> ;;    insert the continuation string
> ;;  insert a carriage return
> ;;  indent according to the major mode in effect
> ;;
> (defun continue-line (&optional targ)
>   "Continue a line based on the major mode that is active in the
> buffer.
>  If there is a continuation string defined for the mode,
>    insert spaces/tabs until the cursor is in the specified column
> (unless the
>      current column is at or beyond the target column, in which case
> insert a
>      single space)
>    insert the continuation string.
>  Insert a carriage return,
>  indent according to the major mode in effect.
> When invoked with a prefix argument the absolute value of the argument
> is used
> as the target column. When invoked without a prefix argument the
> target
> column
> is obtained from the variable cli-targ.  cli-targ is a buffer local
> variable."
>   (interactive "*P")
>   (if (not targ) (setq targ cli-targ))
>   (setq targ (abs targ))
>   (when (cdr (assoc major-mode cli-mode-continuation-str))
>     (if (> targ (current-column))
> 	(move-to-column targ t)
>       (insert " "))
>     (insert (cdr (assoc major-mode cli-mode-continuation-str))))
>   (insert "\n")
>   (indent-according-to-mode))
>
> ;;========<Function>=======<Function>=======<Function>=======<Function
> >=
> ======
> ;; Function: set-continue-column
> ;;
> ;; Psuedo code:
> ;;  if the argument is greater than 0
> ;;  then
> ;;    set the default target value to the argument
> ;;  else
> ;;    issue an error message
> ;;    return nil
> ;;
> (defun set-continue-column (val)
>   "Set the continuation character column for the continue-line
> function.
> The column number must be greater than 0."
>   (interactive "p")
>   (if (> val 0)
>       (setq cli-targ val)
>     (message "Argument greater than 0 is required")
>     nil))
>
> (global-set-key [C-return] 'continue-line)
>
> ;;; END OF continue-line.el
>
>
>
>
> _____________________________________________________________________
> PrivatePhone - FREE telephone number & voicemail.
> A number so private, you can make it public.
> http://www.privatephone.com
>
>
> _____________________________________________________________________
> PrivatePhone - FREE telephone number & voicemail.
> A number so private, you can make it public.
> http://www.privatephone.com

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

end of thread, other threads:[~2006-07-08  8:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-28 19:20 setting continuation chars gamename
2006-06-29  7:38 ` Mathias Dahl
2006-06-29 11:24   ` gamename
  -- strict thread matches above, loose matches on Subject: below --
2006-06-29 20:35 Jay Bingham
     [not found] <mailman.3529.1151613525.9609.help-gnu-emacs@gnu.org>
2006-07-08  8:47 ` gamename

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.