eev
[Top][All Lists]
Advanced

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

Re: wset for frames


From: Eduardo Ochs
Subject: Re: wset for frames
Date: Sat, 6 Nov 2021 03:24:47 -0300

Hi Erich,

in older versions of eev I experimented with many different ways
of writing templates...

Below is my translation of your compose-and-write to my current
favorite style. One of the things that I like most in it is that
I can put tests in comments, like in the ";; Test:" line.


;; Test: (find-estring-elisp (compose-allab "<tla>" "<TLA>" "<fname>"))
;;
(defun compose-allab (tla TLA fname)
  (ee-template0 "
(defun {tla}x (&rest pos-spec-list)
 (interactive)
 (apply 'find-pdf-txt {fname} pos-spec-list))

(defun {TLA}  (&rest pos-spec-list)
 (interactive)
 (find-wset \"F_\" \"{TLA}\" `({tla}x ,@pos-spec-list)))

;; --------------------------------------------------------------------------------
"))

(defun compose-and-write (tla TLA fname)
  (insert (compose-allab tla TLA fname)))


Your trick with the split-string in your write-tlas is really
nice! I would factor your write-tlas in this way to make it
easier to test and to modify:


(defun write-tlas0 (strx)
  (let* ((tlax (nth 1 (split-string strx)))
         (tla  (replace-regexp-in-string "'" "" tlax))
         (TLA (concat (capitalize tla) "x"))
         (fnamex (nth 2 (split-string strx )))
         (fname  (replace-regexp-in-string ")" "" fnamex))
         )
    (compose-allab tla TLA fname)))

(defun write-tlas ()
  (interactive)
  (let* ((line (buffer-substring-no-properties (ee-bol) (ee-eol)))
(allab (write-tlas0 strx)))
    (insert allab)))


What do you think of this?
  Cheers, E. =)


P.S.: I will give a workshop tomorrow and I'm quite tired, so I
won't wrote more ideas now...



On Fri, 5 Nov 2021 at 05:17, Erich Ruff <erich_ruff@t-online.de> wrote:
Good Morning Eduardo,

you proposed to split my function into 2 and use ee-template0 to
construct the cmd-lines:

Here is my working solution: (w/o error checking)
Is this what you meant?
Do you think the code needs impprovement?


------------------------------ code begin --------------------
;; the cmd-line to parse w/o the comment ';;' is:
;; (code-tla-pdf 'fig1 "/mnt/fichte/fuchs_erich-fichte_im_gespraech_1_1762-1798.pdf")

(defun write-tlas ()
  "parse the given code-tla-pdf line"
  (interactive)
  (let* (
         (beg (line-beginning-position))
         (end (line-end-position))
         (strx (buffer-substring-no-properties beg end))
         ;; (strx "code-tla-pdf 'fuch1 /mnt/fichte/fuchs_erich-fichte_im_gespraech_1_1762-1798.pdf")
         (tlax (nth 1 (split-string strx)))
         (tla  (replace-regexp-in-string "'" "" tlax))
         (TLA (concat (capitalize tla) "x"))
         (fnamex (nth 2 (split-string strx )))
         (fname  (replace-regexp-in-string ")" "" fnamex))
         )
    ;; (message "%s -- %s  -- %s"  tla TLA fname)
    (compose-and-write tla TLA fname)
    )
  )


(defun compose-and-write ( tla TLA fname )
  "receive tla TLA and fname from
   parsing function"
  (interactive)
  ;; define all the substrings
  (let* (
         (ia "(interactive)\n")
         (posa  "(&rest pos-spec-list")
         (posb  "pos-spec-list")
         (posc ",@pos-spec-list)))")
         (apply  "(apply 'find-pdf-txt")
         (fwset "(find-wset \"F_\"")
         (xgans "\"" )
         ;; compose the 'tlas' with ee-template0
         (alla (ee-template0 "\n(defun {tla}x {posa} )\n {ia} {apply} {fname} {posb} ))\n"))
         (allb (ee-template0 "\n(defun {TLA}  {posa} )\n {ia} {fwset} {xgans}{TLA}{xgans} `({tla}x {posc}\n"))
         )
    ;; go down, insert 'tlas' and a final seperating line
    (goto-char (line-end-position))
    (insert "\n")
    (insert alla)
    (insert allb)
    (insert "\n;; ")
    (cl-loop for i from 1 to 80 do (insert "-"))
    (insert "\n\n")
    )
  )
------------------------------ code end --------------------





On Di 02 Nov 2021 at 13:30, Eduardo Ochs <eduardoochs@gmail.com> wrote:

> Also here:
>
> http://angg.twu.net/eev-current/eev-template0.el.html#lexical-binding
>
> On Tue, 2 Nov 2021 at 13:26, Eduardo Ochs <eduardoochs@gmail.com> wrote:
>>
>> That's a very good approach!
>>
>> I would rewrite it as two functions: one that just receives tla,
>> TLA, and fname, and uses ee-template0 to produce a big string
>> from them, and a second one that processes the current line,
>> obtains tla, TLA, and fname, calls the first function, and
>> inserts the string that the first one produces. I'll send you
>> some examples later. Ah, btw, I started to rewrite your code with
>> ee-template0, but I didn't finish because I found something more
>> urgent - below.
>>
>> Did you try to use ee-template0? Did you fail? I just wrote an
>> explanation - much better than the previous one - for why it
>> needs dynamic binding... it is here:
>>
>> (find-wgeta-elisp "http://angg.twu.net/eev-current/eev-template0.el"
>> "lexical-binding")
>>
>> More later! =),
>>   Eduardo
>>
>> On Tue, 2 Nov 2021 at 11:51, Erich Ruff <erich_ruff@t-online.de> wrote:
>> >
>> >
>> > Hello Eduardo,
>> >
>> > here is my code - if you can improve it: please do so!
>> >
>> > ----
>> >
>> > if your cursor stands on the line beginning with --> (code-tla-pdf
>> > call --> write-tlas
>> >
>> > (code-tla-pdf 'fig1 "/mnt/fichte/fuchs_erich-fichte_im_gespraech_1_1762-1798.pdf")
>> >
>> >
>> > (defun write-tlas ()
>> >   "take a code-tla-pdf line and create
>> >    defun     to  txt-version of pdf
>> >    find-wset to  open it in a persistent frame"
>> >   (interactive)
>> >   (let* ((beg (line-beginning-position))
>> >          (end (line-end-position))
>> >          (strx (buffer-substring-no-properties beg end))
>> >          (tlax (nth 1 (split-string strx )))
>> >          (tla  (replace-regexp-in-string "'" "" tlax))
>> >          (fnamex (nth 2 (split-string strx )))
>> >          (fname  (replace-regexp-in-string ")" "" fnamex))
>> >          (posa  "(&rest pos-spec-list")
>> >          (posb  "pos-spec-list")
>> >          (ia "(interactive)\n")
>> >          (apply  "(apply 'find-pdf-txt")
>> >          (posz  "pos-spec-list")
>> >          (TLA (concat (capitalize tla) "x"))
>> >          (fwset "(find-wset \"F_\" ")
>> >          (wrest (concat "`(" tla "x"  " ,@pos-spec-list)))"))
>> >          (alla (concat "\n(defun " tla "x" " " posa ")\n" ia " " apply " " fname " " posb "))\n"))
>> >          (allb (concat "\n(defun " TLA " " posa ")\n" ia " " fwset  " \"" TLA "\""  " " wrest "\n"))
>> >          )
>> >     (forward-line 1)
>> >     (insert alla)
>> >     (forward-line 1)
>> >     (insert allb)
>> >     (forward-line 1)
>> >     (insert ";; ")
>> >     (cl-loop for i from 1 to 80 do (insert "-"))
>> >     (insert "\n\n")
>> >     )
>> >   )
>> >
>> > Cheers
>> >  Erich
>> >
>> >
>> > On Di 02 Nov 2021 at 11:25, Eduardo Ochs <eduardoochs@gmail.com> wrote:
>> >
>> > > Please share!
>> > > I'll try to fix find-wset "F".

reply via email to

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