help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: setting continuation chars


From: gamename
Subject: Re: setting continuation chars
Date: 8 Jul 2006 01:47:59 -0700
User-agent: G2/0.2

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]