emacs-devel
[Top][All Lists]
Advanced

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

Re: a ses question


From: Andrés Ramírez
Subject: Re: a ses question
Date: Wed, 01 Nov 2023 17:07:52 +0000

Hi again Vincent.

In the last email was missing the way the code looks now (I am updating
it cos now the ses computation result is recovered on a different way),
see the var mysesoutput.

--8<---------------cut here---------------start------------->8---
;;; with a buffer visiting the file /tmp/smeteroutput (output of smeterApp) run 
this function
(defun smeter/further-processing ()
  "process input on as spreadsheet using ses formulae and extracting the ses 
computation result"
  (interactive)
  (let ( (sesbuf nil)
         (measu nil)
         (prevmeasu '())
         (waterbill nil)
         (beg nil)
         (workbook-filename) myyyyymm mysesoutput)
    (goto-char (point-min))
    (setq beg (point)) (setq workbook-filename (buffer-substring-no-properties 
beg (line-end-position)))
    (forward-line 1)
    (setq beg (point)) (forward-line 4) (setq prevmeasu (split-string 
(buffer-substring-no-properties beg (point)) "\n"))
    (setq beg (point)) (setq waterbill (buffer-substring-no-properties beg 
(line-end-position)))
    (forward-line 1)
    (setq beg (point)) (forward-line 4) (setq measu 
(buffer-substring-no-properties beg (point)))
    (setq beg (point)) (setq myyyyymm (buffer-substring-no-properties beg 
(line-end-position)))
    (if (not (file-readable-p workbook-filename))
        (message (format "file not found: '%s'"  workbook-filename))
      (set-buffer (setq sesbuf (find-file-noselect workbook-filename)))
      (ses-set-cell 12 2 'value (string-to-number waterbill)) ;;; C13
      (ses-set-cell 2 1 'value (string-to-number (nth 0 prevmeasu))) ;;; B3
      (ses-set-cell 3 1 'value (string-to-number (nth 1 prevmeasu)))
      (ses-set-cell 4 1 'value (string-to-number (nth 2 prevmeasu)))
      (ses-set-cell 5 1 'value (string-to-number (nth 3 prevmeasu))) ;;; B6
      ;;; NOTE2ME: yank is needed workaround-one (perhaps cos of deferred 
calculations) ¿How to call manually the deferred-calculation?
      (ses-jump-safe "C3") ;;; paste 4 cells
      (kill-new measu)
      (yank) ;;; how to get rid of yank? 4 using ses-set-cell in place of yank
      ;;; (ses-recalculate-all)
      ;;; NOTE2ME: manual refreshing is needed cos ses-recalculate-all is not 
doing the job (then workaround-two)
      ;;; Key:R1 refreshOne cos of measures (all-refreshes-are-workaround-two)
      ;;; NOTE2ME: It should benefit a lot of persons knowing the right syntax 
4 ses-range
      (let ((minrow 2)(maxrow 5)(mincol 4)(maxcol 5)) (ses-recalculate-cell)) 
;;; E3 F6
      ;;; Key:R2 refreshTwo cos of waterBill-change
      (let ((minrow 2)(maxrow 5)(mincol 7)(maxcol 13)) (ses-recalculate-cell)) 
;;; H3 N6
      ;;; below is for N3 N6 the computation result
      (setq mysesoutput (concat (number-to-string (ses-cell-value 2 13)) "\n" 
(number-to-string (ses-cell-value 3 13)) "\n" (number-to-string (ses-cell-value 
4 13)) "\n" (number-to-string (ses-cell-value 5 13))))
      ;;; kill ses buffer without confirmation (comment 2-lines below for not 
killing workbook-buffer)
      (set-buffer-modified-p nil)
      (let ((kill-buffer-query-functions nil)) (kill-buffer sesbuf))
      ;;;(smeter/compose-mail mysesoutput (- (length prevmeasu) 1) myyyyymm)
      (with-temp-buffer (insert (replace-regexp-in-string "\n" "|" 
mysesoutput)) (write-file "/tmp/smeter-ses-computation-result-on-one-line"))
      ;;;(smeter/receipts-amounts)
      )))
--8<---------------cut here---------------end--------------->8---
Best Regards

--- Begin Message --- Subject: Re: a ses question Date: Mon, 30 Oct 2023 19:03:19 +0000
I just yanked the elisp snippet You shared (without any modification) I
just did M-x eval-defun, and It gave me this error:

--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (error "Eager macro-expansion failure: 
(void-variable ses-...")
  signal(error ("Eager macro-expansion failure: (void-variable ses-..."))
  error("Eager macro-expansion failure: %S" (void-variable ses--cells))
  internal-macroexpand-for-load((setq elisp--eval-defun-result (let 
((print-level nil) (print-length nil)) (defalias 'smeter/further-processing 
#'(lambda nil "process input on as spreadsheet using ses formulae..." 
(interactive) (let (... ... ... ... ... ... myyyyymm mysesoutput chunk 
bigchunk) (goto-char ...) (setq beg ...) (setq workbook-filename ...) 
(forward-line 1) (setq beg ...) (forward-line 4) (setq prevmeasu ...) (setq beg 
...) (setq waterbill ...) (forward-line 1) (setq beg ...) (forward-line 4) 
(setq measu ...) (setq beg ...) (setq myyyyymm ...) (if ... ... ... ... ... ... 
... ... ... ... ... ... ... ... ... ... ... ...)))))) t)
  eval-region(162 5110 t #f(compiled-function (ignore) #<bytecode 
-0x5bb31d1b5fed60e>))  ; Reading at buffer position 2635
  elisp--eval-defun()
  eval-defun(nil)
  funcall-interactively(eval-defun nil)
  call-interactively(eval-defun record nil)
  command-execute(eval-defun record)
  execute-extended-command(nil "eval-defun" "eval-defun")
  funcall-interactively(execute-extended-command nil "eval-defun" "eval-defun")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)
--8<---------------cut here---------------end--------------->8---

Best Regards
Andrés Ramírez
>>>>> "Vincent" == Vincent Belaïche <vincent.b.1@hotmail.fr> writes:

    Vincent>  Just reading again the code which I sent in my
    Vincent> previous email, I found a problem, there would be one trailing 
column separator « & »
    Vincent> too many. Probably the following would be better:

    Vincent> (let ((range (with-current-buffer the-ses-buffer (ses-range A1 C3 
; adapt to your case
    Vincent> 
                                          
 *2 '>v ; use 'v> to read columnwsise
    Vincent> 
                                          
 )))) (dolist (row (cdr range)) ; cdr to
    Vincent> remove 'vec (pop row) ; remove 'vec (while (progn 
       (insert (format "%f" (pop
    Vincent> row))) ; assuming all cells are floating point numbers 
       (when row        (insert
    Vincent>        "&" ; if & is the column separator 
       ) t ; loop again              )))
    Vincent> (insert "\\\\\n"; if \\ is the row separator        )))

--- End Message ---

reply via email to

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