Author Topic: Continue loading files in start-up file.  (Read 442 times)

0 Members and 1 Guest are viewing this topic.

dubb

  • Swamp Rat
  • Posts: 1059
Continue loading files in start-up file.
« on: February 05, 2019, 02:52:11 PM »
In the startup file I load all of the lisp scripts one by one.
Code: [Select]
(load "abc")
(load "123")
(load "etc.....")
if one of those lisp files do not load, I wish to continue onto the next line of code or continue loading the next lisp file. Is this possible?

Lee Mac

  • Seagull
  • Posts: 12264
  • London, England
Re: Continue loading files in start-up file.
« Reply #1 on: February 05, 2019, 03:03:12 PM »
Code - Auto/Visual Lisp: [Select]
  1. (load "abc" nil)

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1368
  • class keyThumper<T>:ILazy<T>
Re: Continue loading files in start-up file.
« Reply #2 on: February 05, 2019, 03:21:50 PM »
OR

Code - Auto/Visual Lisp: [Select]
  1. (load "123" "File load '123' failed ... ")
called Kerry in my other life

Sometimes the question is more important than the answer.
#ridesober

dubb

  • Swamp Rat
  • Posts: 1059
Re: Continue loading files in start-up file.
« Reply #3 on: February 05, 2019, 03:57:28 PM »
Thanks! I didn't know "LOAD" can take more than one argument.

Lee Mac

  • Seagull
  • Posts: 12264
  • London, England
Re: Continue loading files in start-up file.
« Reply #4 on: February 05, 2019, 04:05:23 PM »
OR

Code - Auto/Visual Lisp: [Select]
  1. (load "123" "File load '123' failed ... ")

Unfortunately such messages would not be printed to the command-line unless the load expression were the last in the sequence of evaluation...

In the past I've considered using something like:
Code - Auto/Visual Lisp: [Select]
  1. (eval (load "123" '(princ "\n123 failed to load...")))
But this can cause issues if the AutoLISP file 123 returns an expression on loading that causes eval to either error or perform an undesired operation on load.

An alternative might be:
Code - Auto/Visual Lisp: [Select]
  1. (if (= 'some-obscure-symbol (load "abc" 'some-obscure-symbol))
  2.     (princ "\nabc failed to load.")
  3. )
With the symbol obscure enough to avoid the possibility of causing a false-negative since one could not determine the return value of the file to be loaded ahead of time.

dubb

  • Swamp Rat
  • Posts: 1059
Re: Continue loading files in start-up file.
« Reply #5 on: February 05, 2019, 04:26:57 PM »
Say if one of my scripts has a bug.
123.lsp contains a malformed list.
Code: [Select]
error: malformed list on input
Code: [Select]
(load "123" "Failed") will  break the start up file.
What could I do to continue loading the next script?


OR

Code - Auto/Visual Lisp: [Select]
  1. (load "123" "File load '123' failed ... ")

Unfortunately such messages would not be printed to the command-line unless the load expression were the last in the sequence of evaluation...

In the past I've considered using something like:
Code - Auto/Visual Lisp: [Select]
  1. (eval (load "123" '(princ "\n123 failed to load...")))
But this can cause issues if the AutoLISP file 123 returns an expression on loading that causes eval to either error or perform an undesired operation on load.

An alternative might be:
Code - Auto/Visual Lisp: [Select]
  1. (if (= 'some-obscure-symbol (load "abc" 'some-obscure-symbol))
  2.     (princ "\nabc failed to load.")
  3. )
With the symbol obscure enough to avoid the possibility of causing a false-negative since one could not determine the return value of the file to be loaded ahead of time.

Lee Mac

  • Seagull
  • Posts: 12264
  • London, England
Re: Continue loading files in start-up file.
« Reply #6 on: February 05, 2019, 04:30:57 PM »
Sledgehammer approach:
Code - Auto/Visual Lisp: [Select]
  1. (vl-catch-all-apply 'load '("123"))

MP

  • Seagull
  • Posts: 17437
Re: Continue loading files in start-up file.
« Reply #7 on: February 05, 2019, 05:08:31 PM »
if one of my scripts has a bug.
123.lsp contains a malformed list.
Code: [Select]
error: malformed list on input
Code: [Select]
(load "123" "Failed") will  break the start up file.

What could I do to continue loading the next script?

Fix 123.lsp. :P

Kidding aside, note that you can catch (and report) error messages captured by vl-catch-all-apply whilst continuing on with execution (if that's desirable). Read up on vl-catch-all-apply, vl-catch-all-error-p and vl-catch-all-error-msg functions (failing latter spoon feeding).
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

dubb

  • Swamp Rat
  • Posts: 1059
Re: Continue loading files in start-up file.
« Reply #8 on: February 05, 2019, 07:30:13 PM »
You know what, you are right. I have to make sure the code is stable and ready to use. What happened was, I left for vacation and there was some code I worked on that had an extra parenthesis. Which prevented the startup file from executing every line.

if one of my scripts has a bug.
123.lsp contains a malformed list.
Code: [Select]
error: malformed list on input
Code: [Select]
(load "123" "Failed") will  break the start up file.

What could I do to continue loading the next script?

Fix 123.lsp. :P

Kidding aside, note that you can catch (and report) error messages captured by vl-catch-all-apply whilst continuing on with execution (if that's desirable). Read up on vl-catch-all-apply, vl-catch-all-error-p and vl-catch-all-error-msg functions (failing latter spoon feeding).