From: Gennady Agranov
Subject: indent for lisp sources
Date: 
Message-ID: <3857BEBC.E8A8A450@synquiry.com>
Hi!

Does anybody knows about indent/format utility (or Emacs
package) for LISP programs ?


Thanks,
 Gennady

From: Eugene Zaikonnikov
Subject: Re: indent for lisp sources
Date: 
Message-ID: <945276562.817473@lxms.cit.org.by>
Gennady Agranov <·······@synquiry.com> wrote in message
······················@synquiry.com...
>
>
> Hi!
>
> Does anybody knows about indent/format utility (or Emacs
> package) for LISP programs ?
>
M-x lisp-mode

Also take a look at http://ilisp.cons.org

--
  Eugene
  (concatenate 'string "viking" ·@" "cit.org.by")
From: Gennady Agranov
Subject: Re: indent for lisp sources
Date: 
Message-ID: <3857D45E.F2257B84@synquiry.com>
I always thought that Emacs "Lisp Indent" allows only to indent the
existing lines,
but not to reformat.  In my particular example I have files with long
lines - how can I
nicely convert them to files with maximum length of 79 characters ?

Thanks,
Gennady

PS. I am going to investigate  http://ilisp.cons.org
(thanks for the URL)


Eugene Zaikonnikov wrote:

> Gennady Agranov <·······@synquiry.com> wrote in message
> ······················@synquiry.com...
> >
> >
> > Hi!
> >
> > Does anybody knows about indent/format utility (or Emacs
> > package) for LISP programs ?
> >
> M-x lisp-mode
>
> Also take a look at http://ilisp.cons.org
>
> --
>   Eugene
>   (concatenate 'string "viking" ·@" "cit.org.by")
From: David J. Cooper
Subject: Re: indent for lisp sources
Date: 
Message-ID: <385796A2.C950F087@genworks.com>
Gennady Agranov wrote:
> 
> I always thought that Emacs "Lisp Indent" allows only to indent the
> existing lines,
> but not to reformat.  In my particular example I have files with long
> lines - how can I
> nicely convert them to files with maximum length of 79 characters ?
> 
> Thanks,
> Gennady
> 

Look at the Common Lisp function PPRINT.

Also look at the parameters *PRINT-RIGHT-MARGIN* and *PRINT-CASE*,
which you can bind (using LET) wrapped around a call to PPRINT.


I would not recommend actually changing things like *PRINT-RIGHT-MARGIN*
or *PRINT-CASE* with setq or setf.


 -dave


-- 
David J. Cooper Jr, Chief Engineer	Genworks International
·······@genworks.com			5777 West Maple, Suite 130
(248) 932-2512 (Genworks HQ/voicemail)	West Bloomfield, MI 48322-2268
(248) 407-0633 (pager)			http://www.genworks.com
From: Marco Antoniotti
Subject: Re: indent for lisp sources
Date: 
Message-ID: <lwhfhh9aqt.fsf@parades.rm.cnr.it>
Gennady Agranov <·······@synquiry.com> writes:

> I always thought that Emacs "Lisp Indent" allows only to indent the
> existing lines,
> but not to reformat.  In my particular example I have files with long
> lines - how can I
> nicely convert them to files with maximum length of 79 characters ?
> 
> Thanks,
> Gennady
> 
> PS. I am going to investigate  http://ilisp.cons.org
> (thanks for the URL)
> 
> 
> Eugene Zaikonnikov wrote:
> 
> > Gennady Agranov <·······@synquiry.com> wrote in message
> > ······················@synquiry.com...
> > >
> > >
> > > Hi!
> > >
> > > Does anybody knows about indent/format utility (or Emacs
> > > package) for LISP programs ?
> > >
> > M-x lisp-mode
> >
> > Also take a look at http://ilisp.cons.org

ILISP does not do indentation.  That is left to Emacs.  Getting Emacs
to do "the right thing" for CL is not so easy.  I still have not found
(I am lazy) a good way to make Emacs indent

	(defmethod m :after ((x symbol))
           (do-something-with x))

in an acceptable way.

Cheers

-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa
From: Bernhard Pfahringer
Subject: Re: indent for lisp sources
Date: 
Message-ID: <83d3ef$2vsc$1@www.univie.ac.at>
In article <··············@parades.rm.cnr.it>,
Marco Antoniotti  <·······@parades.rm.cnr.it> wrote:
>
>ILISP does not do indentation.  That is left to Emacs.  Getting Emacs
>to do "the right thing" for CL is not so easy.  I still have not found
>(I am lazy) a good way to make Emacs indent
>
>	(defmethod m :after ((x symbol))
>           (do-something-with x))
>
>in an acceptable way.
>

Hi,

I'm using "cl-indent", which indents the above as:

(defmethod m :after ((x symbol))
  (do-something-with x))

which is fine for me. Unfortunately LOOP-handling is still less
than optimal.
From the header of this file:

;;; cl-indent.el --- enhanced lisp-indent mode

;; Copyright (C) 1987 Free Software Foundation, Inc.

;; Author: Richard Mlynarik <···@eddie.mit.edu>
;; Created: July 1987
;; Maintainer: FSF
;; Keywords: lisp, tools

;; This file is part of XEmacs.

;; XEmacs 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.

;; XEmacs 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 XEmacs; see the file COPYING.  If not, write to the Free
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
;; 02111-1307, USA.

;;; Synched up with: FSF 19.34

;;; Commentary:

;; This package supplies a single entry point, common-lisp-indent-function,
;; which performs indentation in the preferred style for Common Lisp code.
;; To enable it:
;;
;; (setq lisp-indent-function 'common-lisp-indent-function)



-- 
--------------------------------------------------------------------------
Bernhard Pfahringer
Austrian Research Institute for  http://www.ai.univie.ac.at/~bernhard/
Artificial Intelligence          ········@ai.univie.ac.at 
From: Marco Antoniotti
Subject: Re: indent for lisp sources
Date: 
Message-ID: <lwd7s58z7w.fsf@parades.rm.cnr.it>
········@hummel.ai.univie.ac.at (Bernhard Pfahringer) writes:

> In article <··············@parades.rm.cnr.it>,
> Marco Antoniotti  <·······@parades.rm.cnr.it> wrote:
> >
> >ILISP does not do indentation.  That is left to Emacs.  Getting Emacs
> >to do "the right thing" for CL is not so easy.  I still have not found
> >(I am lazy) a good way to make Emacs indent
> >
> >	(defmethod m :after ((x symbol))
> >           (do-something-with x))
> >
> >in an acceptable way.
> >
> 
> Hi,
> 
> I'm using "cl-indent", which indents the above as:
> 
> (defmethod m :after ((x symbol))
>   (do-something-with x))
> 
> which is fine for me. Unfortunately LOOP-handling is still less
> than optimal.

This is what I use.  Do you have soem special tricks laying around?

Cheers

-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa
From: Bernhard Pfahringer
Subject: Re: indent for lisp sources
Date: 
Message-ID: <83dhru$6df6$1@www.univie.ac.at>
In article <··············@parades.rm.cnr.it>,
Marco Antoniotti  <·······@parades.rm.cnr.it> wrote:
>
>········@hummel.ai.univie.ac.at (Bernhard Pfahringer) writes:
>
>> In article <··············@parades.rm.cnr.it>,
>> Marco Antoniotti  <·······@parades.rm.cnr.it> wrote:
>> >
>> >ILISP does not do indentation.  That is left to Emacs.  Getting Emacs
>> >to do "the right thing" for CL is not so easy.  I still have not found
>> >(I am lazy) a good way to make Emacs indent
>> >
>> >	(defmethod m :after ((x symbol))
>> >           (do-something-with x))
>> >
>> >in an acceptable way.
>> >
>> 
>> Hi,
>> 
>> I'm using "cl-indent", which indents the above as:
>> 
>> (defmethod m :after ((x symbol))
>>   (do-something-with x))
>> 
>> which is fine for me. Unfortunately LOOP-handling is still less
>> than optimal.
>
>This is what I use.  Do you have soem special tricks laying around?
>

Looking at "cl-indent.el", I have found what may be the explanation:

;; XEmacs change
(defun lisp-indent-defmethod (path state indent-point
                              sexp-column normal-indent)
  ;; Look for a method combination specifier...
  (let* ((combined (if (and (>= (car path) 3)
                            (null (cdr path)))
                       (save-excursion
                         (goto-char (car (cdr state)))
                         (forward-char)
                         (forward-sexp)
                         (forward-sexp)
                         (forward-sexp)
                         (backward-sexp)
                         (if (looking-at ":")
                             t
                             nil))
                       nil))
         (method (if combined
                     '(4 4 (&whole 4 &rest 1) &body)
                     '(4 (&whole 4 &rest 1) &body))))
    (funcall (function lisp-indent-259)
             method
             path state indent-point sexp-column normal-indent)))


And of course the setup is such that:

 (get 'defmethod 'common-lisp-indent-function)

returns: lisp-indent-defmethod

Is this exactly the same to your setup?

Bernhard
-- 
--------------------------------------------------------------------------
Bernhard Pfahringer
Austrian Research Institute for  http://www.ai.univie.ac.at/~bernhard/
Artificial Intelligence          ········@ai.univie.ac.at 
From: Shin
Subject: Re: indent for lisp sources
Date: 
Message-ID: <385a125a.7227411@news.iddeo.es>
On 17 Dec 1999 10:28:58 +0100, Marco Antoniotti <·······@parades.rm.cnr.it>
wrote:

: > I always thought that Emacs "Lisp Indent" allows only to indent the
: > existing lines,
: > but not to reformat.  In my particular example I have files with long
: > lines - how can I
: > nicely convert them to files with maximum length of 79 characters ?

: > Eugene Zaikonnikov wrote:
: > 
: > > Gennady Agranov <·······@synquiry.com> wrote in message
: > > ······················@synquiry.com...
: > > >
: > > >
: > > > Hi!
: > > >
: > > > Does anybody knows about indent/format utility (or Emacs
: > > > package) for LISP programs ?
: > > >
: > > M-x lisp-mode
: > >
: > > Also take a look at http://ilisp.cons.org
: 
: ILISP does not do indentation.  That is left to Emacs.  Getting Emacs
: to do "the right thing" for CL is not so easy.  I still have not found
: (I am lazy) a good way to make Emacs indent
: 
: 	(defmethod m :after ((x symbol))
:            (do-something-with x))
: 
: in an acceptable way.

In the /doc directory of CLISP there is a most helpful file called
editors.txt that, among other things, comes with hints on this.

I haven't tried them because I use Vim, but they seem appropriate
to the thread.

Regards,

-- Shin


* How to customize Emacs for use of CLISP?

  1. When you load a Lisp file (extension ".lsp") into Emacs, it
     automatically switches to lisp-mode, magically by a variable
     called auto-mode-alist.
     One feature of the lisp-mode is that the tab key indents the current
     line, which makes typing Lisp programs easier because you don't have
     to type the whitespace. Unfortunately, this also educates you to lazily
     put all closing parentheses at the end of the line, instead of closing
     them - with thought - one by one.
     The lisp-mode is not well suited for Common Lisp. In particular, IF
     forms get badly indented. To fix this, add the following to your
     .emacs:

         ;; Common Lisp indentation.
         (load-library "cl-indent")
         (add-hook 'lisp-mode-hook
           (lambda ()
             (setq lisp-indent-function 'common-lisp-indent-function)
         ) )
         ;; Additional definitions by Pierpaolo Bernardi.
         (defun cl-indent (sym indent)
           (put sym 'common-lisp-indent-function
             (if (symbolp indent)
               (get indent 'common-lisp-indent-function)
               indent
         ) ) )
         (cl-indent 'if '1)
         (cl-indent 'defclass '((&whole 4 &rest (&whole 2 &rest 1))
                                &rest (&whole 2 &rest 1)))
         (cl-indent 'defgeneric 'defun)
         (cl-indent 'defmethod '(4 4 (&whole 4 &rest 1) &body))
         (cl-indent 'generic-flet 'flet)
         (cl-indent 'generic-labels 'labels)
         (cl-indent 'symbol-macrolet 'multiple-value-bind)
         (cl-indent 'with-accessors 'multiple-value-bind)
         (cl-indent 'with-added-methods '((1 4 ((&whole 1))) (2 &body)))
         (cl-indent 'with-slots 'multiple-value-bind)
         (cl-indent 'handler-bind '((&whole 4 &rest 1) 2 &body))
         (cl-indent 'handler-case '((1 4) (&whole 2 ((0 1) (1 3) (2 &body)))))
         (cl-indent 'define-condition '((1 6)
                                        (2 6 ((&whole 1)))
                                        (3 4 ((&whole 1)))
                                        (4 &body)))
         (cl-indent 'restart-bind '(((&whole 2 (0 1) (&whole 1))) (2 &body)))
         (cl-indent 'restart-case '((1 4) (&whole 2 ((0 1) (&whole 1)))))
         (cl-indent 'with-condition-restarts '((1 4 ((&whole 1))) (2 &body)))
         (cl-indent 'with-simple-restart '((1 4 ((&whole 1))) (2 &body)))

  2. If you still have problems with parentheses and indentation,
     try out the mode-motion package. When you move the mouse cursor on
     an opening parenthesis, it highlights the entire Lisp expression.
     Very nice for checking badly indented Lisp code.
     Insert into your .emacs:

         ;; Visualizing Lisp forms.
         (let ((hook
                 (lambda ()
                   (setq mode-motion-hook 'mode-motion-highlight-sexp))))
           (add-hook 'emacs-lisp-mode-hook hook t)
           (add-hook 'lisp-interaction-mode-hook hook t)
           (add-hook 'lisp-mode-hook hook t)
           (add-hook 'inferior-lisp-mode-hook hook t)
           (add-hook 'talk-mode-hook hook t)
         )

  3. You might try out syntactic colouring of your Lisp programs.
     Just after loading the first Lisp file into Emacs, type
     M-x font-lock-mode.
     Well, some people like it, some don't.

  4. Now, the easiest way to start clisp within Emacs, is M-x shell,
     and at the shell prompt type

         $ clisp

     In this mode, you cycle through the history using M-p (not C-p
     as with the readline library). Also, to retry a command, just
     place the cursor at the beginning of the command and type
     Return (in XEmacs) or C-c Return (in GNU Emacs).

  5. There is a better Emacs mode, called inferior-lisp-mode.
     CLISP is by no means "inferior" to Emacs Lisp (rather the contrary),
     but CLISP in then turning as a kind of "server", with Emacs as "client".
     For this, add to your .emacs:

         ;; XEmacs doesn't autoload inf-lisp.el, load it now.
         (load-library "inf-lisp")
         ;; Define the program to be called by M-x run-lisp.
         (setq inferior-lisp-program "clisp -I -q")
         ;; Add new keybindings: C-x C-e evaluates the *next* form,
         ;; C-x C-m macroexpands the next form.
         (defun lisp-eval-sexp (&optional and-go)
           "Send the next sexp to the inferior Lisp process.
            Prefix argument means switch to the Lisp buffer afterwards."
           (interactive "P")
           (lisp-eval-region (point)
                             (save-excursion (forward-sexp) (point))
                             and-go
         ) )
         (defun lisp-macroexpand-region (start end &optional and-go)
           "Macroexpand the current region in the inferior Lisp process.
            Prefix argument means switch to the Lisp buffer afterwards."
           (interactive "r\nP")
           (comint-send-string
            (inferior-lisp-proc)
            (format "(macroexpand-1 (quote %s))\n" (buffer-substring start end))
           )
           (if and-go (switch-to-lisp t))
         )
         (defun lisp-macroexpand-sexp (&optional and-go)
           "Macroexpand the next sexp in the inferior Lisp process.
            Prefix argument means switch to the Lisp buffer afterwards."
           (interactive "P")
           (lisp-macroexpand-region (point)
                                    (save-excursion (forward-sexp) (point))
                                    and-go
         ) )
         ;; Define the great keybindings.
         (inferior-lisp-install-letter-bindings)
         (define-key lisp-mode-map          "\C-x\C-e" 'lisp-eval-sexp)
         (define-key inferior-lisp-mode-map "\C-x\C-e" 'lisp-eval-sexp)
         (define-key lisp-mode-map          "\C-x\C-m" 'lisp-macroexpand-sexp)
         (define-key inferior-lisp-mode-map "\C-x\C-m" 'lisp-macroexpand-sexp)

     The "-I" is important. The "-q" is only needed if the banner annoys you.
     Then start CLISP by the command M-x run-lisp.
     In this mode, M-p cycles through the history, as above, but C-c Return
     doesn't work. The keybinding C-x C-e, which may also be issued from
     another lisp-mode buffer, evaluates the form before(!) the cursor.

     If you want to start clisp in different configurations, you can make
     different commands for it, like this:

         (defun clisp ()
           (interactive)
           (setq inferior-lisp-program "clisp -I -q")
           (run-lisp inferior-lisp-program))
         (defun clx ()
           (interactive)
           (setq inferior-lisp-program "clx -I -q")
           (run-lisp inferior-lisp-program))
         (defun garnet ()
           (interactive)
           (setq inferior-lisp-program "garnet -I -q")
           (run-lisp inferior-lisp-program))

  6. There is an even better Emacs mode, called ilisp-mode.
     [Merge here stuff from Marcus, Matthias, Peter.??]
     XEmacs 19.14 comes with ILISP version 5.7. A newer version is at
     ftp://ftp.icsi.berkeley.edu/pub/software/elisp/ilisp-5.8*.tar.gz .

: 
: -- 
: Marco Antoniotti ===========================================
: PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
: tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
: http://www.parades.rm.cnr.it/~marcoxa
From: Marco Antoniotti
Subject: Re: indent for lisp sources
Date: 
Message-ID: <lwemcke7zu.fsf@parades.rm.cnr.it>
···@retemail.es (Shin) writes:

>   6. There is an even better Emacs mode, called ilisp-mode.
>      [Merge here stuff from Marcus, Matthias, Peter.??]
>      XEmacs 19.14 comes with ILISP version 5.7. A newer version is at
>      ftp://ftp.icsi.berkeley.edu/pub/software/elisp/ilisp-5.8*.tar.gz .

BTW. ILISP is now at version 5.9.2 and its official home is

	http://ilisp.cons.org

(YES. It is back on line)

I will remove the stuff at icsi.berkeley.edu soon.

Cheers

-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa
From: Marco Antoniotti
Subject: Re: indent for lisp sources
Date: 
Message-ID: <lwhfhge85d.fsf@parades.rm.cnr.it>
Thanks. (to you and to Bernhard)

This was most helpful.  I do not use XEmacs and have only recently
installed CLisp.

Cheers

-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa