all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: a ses question
@ 2023-11-01 17:07 Andrés Ramírez
  0 siblings, 0 replies; 27+ messages in thread
From: Andrés Ramírez @ 2023-11-01 17:07 UTC (permalink / raw)
  To: Vincent Belaïche; +Cc: emacs-devel, boruch_baum

[-- Attachment #1: Type: text/plain, Size: 3502 bytes --]

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


[-- Attachment #2: Type: message/rfc822, Size: 3170 bytes --]

From: andrés ramírez <rrandresf@hotmail.com>
To: Vincent Belaïche <vincent.b.1@hotmail.fr>
Cc: emacs-devel <emacs-devel@gnu.org>, boruch_baum@gmx.com
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        )))

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2023-12-27 17:42 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <SJ1PR12MB6363EAEDEA36DA78E736B9DEA61EA@SJ1PR12MB6363.namprd12.prod.outlook.com>
2023-10-29 16:43 ` a ses question Vincent Belaïche
2023-10-29 21:25   ` Vincent Belaïche
2023-10-30  5:43     ` Vincent Belaïche
2023-10-30 19:03       ` andrés ramírez
2023-11-01 19:08         ` Vincent Belaïche
2023-11-01 19:23           ` Vincent Belaïche
2023-11-02 11:20             ` Vincent Belaïche
2023-11-02 11:27               ` Vincent Belaïche
2023-11-02 11:31                 ` Vincent Belaïche
2023-11-02 18:19                 ` Stefan Monnier
2023-11-03 15:54                   ` Vincent Belaïche
2023-11-03 22:13                     ` Vincent Belaïche
2023-11-04 13:46                       ` andrés ramírez
     [not found]                       ` <SJ1PR12MB636334BD471403C3F936BF25A6A4A@SJ1PR12MB6363.namprd12.prod.outlook.com>
2023-11-05 10:25                         ` using ses programatically (was: a ses question) Vincent Belaïche
2023-11-05 14:58                           ` andrés ramírez
2023-11-05 16:55                             ` Vincent Belaïche
2023-11-05 19:33                               ` andrés ramírez
2023-11-18 22:55                                 ` Vincent Belaïche
2023-11-19 19:24                                   ` andrés ramírez
2023-11-19 23:18                                     ` Vincent Belaïche
2023-11-19 23:24                                       ` Vincent Belaïche
2023-11-20  0:33                                         ` andrés ramírez
2023-12-24 11:51                                           ` Vincent Belaïche
2023-12-24 15:44                                             ` andrés ramírez
2023-12-24 21:13                                               ` Vincent Belaïche
2023-12-27 17:42                                                 ` Vincent Belaïche
2023-11-01 17:07 a ses question Andrés Ramírez

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.