Author Topic: System Variable trustedpaths and over write exist  (Read 1657 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
System Variable trustedpaths and over write exist
« on: September 17, 2015, 05:29:24 AM »
trying to add this part of code in startup but makes duplicate of path.
I am wondering is there a way to avoid this duplicate
Code - Auto/Visual Lisp: [Select]
  1. (if (setq CrntTrstPth (getvar "TRUSTEDPATHS")) ;LEE
  2.   (progn
  3.     (setq Pth1 "C:\\LISP1\\..." )
  4.     (setq Pth2 "C:\\LISP2\\...")
  5.     (setvar "TRUSTEDPATHS" (strcat CrntTrstPth ";" Pth1 ";" Pth2))
  6.     ))

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: System Variable trustedpaths and over write exist
« Reply #1 on: September 17, 2015, 06:47:34 AM »
You could use a function such as:
Code - Auto/Visual Lisp: [Select]
  1. ;; Add Paths  -  Lee Mac
  2. ;; Adds a list of paths to a semi-colon delimited string, excluding duplicates and invalid paths.
  3. ;; cur - [str] Semi-colon delimited string representing existing set of paths
  4. ;; new - [lst] list of paths to add, e.g. '("C:\\Folder1" "C:\\Folder2" ... )
  5. ;; Returns: [str] Supplied string following modification
  6.  
  7. (defun LM:addpaths ( cur new )
  8.     (if (wcmatch cur "*[~;]") (setq cur (strcat cur ";")))
  9.     (strcat cur
  10.         (apply 'strcat
  11.             (vl-remove-if
  12.                '(lambda ( x )
  13.                     (or (vl-string-search (strcase x) (strcase cur))
  14.                         (not (findfile (vl-string-right-trim ";" x)))
  15.                     )
  16.                 )
  17.                 (mapcar
  18.                    '(lambda ( x )
  19.                         (strcat (vl-string-right-trim "\\" (vl-string-translate "/" "\\" x)) ";")
  20.                     )
  21.                     new
  22.                 )
  23.             )
  24.         )
  25.     )
  26. )
Code - Auto/Visual Lisp: [Select]
  1. (if (getvar 'trustedpaths)
  2.     (setvar 'trustedpaths (LM:addpaths (getvar 'trustedpaths) '("C:\\LISP1\\..." "C:\\LISP2\\...")))
  3. )

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: System Variable trustedpaths and over write exist
« Reply #2 on: September 17, 2015, 07:14:22 AM »
You could use a function such as:
...
As usual AWESOME
Thanks LEE

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: System Variable trustedpaths and over write exist
« Reply #3 on: September 17, 2015, 07:58:08 AM »
You're welcome Hasan  :-)