Results 1 to 5 of 5

Thread: ESC use with lisp

  1. #1
    100 Club
    Join Date
    2012-11
    Posts
    102

    Default ESC use with lisp

    Hey all

    Is there an wasy way of writing your lisps so that if the user presses the escape key during its execution that it exits the program in a desired way? eg restoring settings such as filedia and tilemode before exiting.

    Cheers

  2. #2
    AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL
    Posts
    1,098

    Default Re: ESC use with lisp

    Post by the offical *error* routine guru:
    http://forums.augi.com/showthread.ph...122#post996122
    Man has taught classes on the subject here on AUGI.
    Tom Beauford P.S.M. - Civil 2013 on Windows 7 Pro
    Design Analysis - Leon County Public Works/Engineering
    2280 Miccosukee Rd. Tallahassee, FL 32308-5310
    Ph# (850)606-1516

  3. #3
    Past Vice President peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu Hawaii
    Posts
    574

    Default Re: ESC use with lisp

    Quote Originally Posted by matthew.e.mortimer342462 View Post
    Hey all

    Is there an wasy way of writing your lisps so that if the user presses the escape key during its execution that it exits the program in a desired way? eg restoring settings such as filedia and tilemode before exiting.

    Cheers
    Here is an example of what I think you want...

    Code:
    (defun C:TestEscape (/ *error* intCmdEcho strMessage)
     (setq intCmdEcho (getvar "cmdecho"))
     (setvar "cmdecho" 0)
     (defun *error* (strMessage)
      (setvar "cmdecho" intCmdEcho)
      (princ strMessage)
      (princ)
     )
     (print "Do Something: ")
     (setvar "cmdecho" intCmdEcho)
     (princ)
    )
    AUGI Volunteer

  4. #4
    Moderator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    2,391

    Default Re: ESC use with lisp

    I prefer to nest the *error* function within the main code, defining the function as a local variable... I also choose to define the localized *error* handler immediately (prior to any system variable changes are made, etc.). While unlikely if not prompting the user for input, it is possible for one to immediately hit escape after a system variable has been changed, and before the *error* handler has been defined, which would result in a system variable value not being restored.

    Example:

    Code:
    (defun c:FOO ( / *error* oldCmdecho foo)
    
      (defun *error* (msg)
        (if oldCmdecho
          (setvar 'cmdecho oldCmdecho)
        )
        (cond ((not msg))                                                   ; Normal exit
              ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
              ((princ (strcat "\n** Error: " msg " ** ")))
        )                                                                   ; Fatal error, display it
        (princ)
      )
    
      (if (and (setq oldCmdecho (getvar 'cmdecho))
               (setq foo (getstring "\nHit <ESC>))
          )
        (prompt "\n** You didn't hit <ESC> like I asked you to ** ")
      )
      (*error* nil)
    )
    "Potential has a shelf life." - Margaret Atwood

  5. #5
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2007-07
    Location
    Jo'burg SA
    Posts
    4,344

    Default Re: ESC use with lisp

    Another thread discussing the use of nested and global error handlers at length: http://forums.augi.com/showthread.ph...Error-Handling
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

Similar Threads

  1. Replies: 1
    Last Post: 2012-04-30, 07:02 PM
  2. Replies: 9
    Last Post: 2012-01-21, 06:58 AM
  3. LISP Debug Broken - Need Lisp to VBA Convert Help
    By bsardeson in forum VBA/COM Interop
    Replies: 4
    Last Post: 2010-10-06, 05:37 PM
  4. Replies: 2
    Last Post: 2008-02-01, 08:05 PM
  5. non lisp cursor location for lisp getpoint
    By dtuttle in forum AutoLISP
    Replies: 3
    Last Post: 2005-05-10, 11:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •