[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] lisp/org-table.el: Allow named columns on lhs
From: |
Gavin Downard |
Subject: |
Re: [PATCH] lisp/org-table.el: Allow named columns on lhs |
Date: |
Sat, 22 Jul 2023 11:21:59 -0700 |
User-agent: |
mu4e 1.10.4; emacs 29.0.92 |
Max Nikulin <manikulin@gmail.com> writes:
> On 19/07/2023 09:36, Gavin Downard wrote:
>> +++ b/lisp/org-table.el
>> @@ -2253,8 +2253,7 @@ LOCATION is a buffer position, consider the formulas
>> there."
>> ((not (match-end 2)) m)
>> ;; Is it a column reference?
>> ((string-match-p "\\`\\$\\([0-9]+\\|[<>]+\\)\\'" m) m)
>> - ;; Since named columns are not possible in
>> - ;; LHS, assume this is a named field.
>> + ;; This is either a named field or column.
>> (t (match-string 2 string)))))
>> (rhs (match-string 3 string)))
>> (push (cons lhs rhs) eq-alist)
>
> Notice
> "Double definition `%s=' in TBLFM line, please fix by hand"
>
> below. A bit more code is required to keep this sanity check for named
> columns.
>
Oh, good catch. Specifically, I think this should be caught inside of
`org-table-recalculate', where it catches conflicting direct column
references (eg "$1") and end-relative column references ("$<").
> let* ((rhs (org-table-formula-substitute-names
> (org-table-formula-handle-first/last-rc (cdr eq))))
> (old-lhs (car eq))
> (lhs
> (org-table-formula-handle-first/last-rc
> (cond
> ((string-match "\\`@-?I+" old-lhs)
> (user-error "Can't assign to hline relative reference"))
> ((string-match "\\`\\$[<>]" old-lhs)
> (let ((new (org-table-formula-handle-first/last-rc
> old-lhs)))
> (when (assoc new eqlist)
> (user-error "\"%s=\" formula tries to overwrite \
> existing formula for column %s"
^ right here
> old-lhs
> new))
> new))
> (t old-lhs)))))
Also, this should probably be addressed in a different patch, but the
above code doesn't catch two different end-relative column references
that refer to the same column, such as "$<" and "$>>" in a two-column table.
I have also modified the manual to reflect the addition of named
columns; I'll send an updated patch after I add the check for double
definitions.
Max Nikulin <manikulin@gmail.com> writes:
>
> `if-let' is not available in Emacs-26
>
Are you sure? It looks like `if-let' was introduced in Emacs 25.
- [PATCH] lisp/org-table.el: Allow named columns on lhs, Gavin Downard, 2023/07/18
- Re: [PATCH] lisp/org-table.el: Allow named columns on lhs, Ihor Radchenko, 2023/07/19
- Re: [PATCH] lisp/org-table.el: Allow named columns on lhs, Max Nikulin, 2023/07/21
- Re: [PATCH] lisp/org-table.el: Allow named columns on lhs, Gavin Downard, 2023/07/21
- Re: [PATCH] lisp/org-table.el: Allow named columns on lhs, Max Nikulin, 2023/07/21
- Re: [PATCH] lisp/org-table.el: Allow named columns on lhs, Ihor Radchenko, 2023/07/22
- Re: [PATCH] lisp/org-table.el: Allow named columns on lhs, Max Nikulin, 2023/07/22
- Re: [PATCH] lisp/org-table.el: Allow named columns on lhs, Ihor Radchenko, 2023/07/22
Re: [PATCH] lisp/org-table.el: Allow named columns on lhs, Max Nikulin, 2023/07/22
- Re: [PATCH] lisp/org-table.el: Allow named columns on lhs,
Gavin Downard <=
Re: [PATCH] lisp/org-table.el: Allow named columns on lhs, Max Nikulin, 2023/07/24