emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Gavin Downard <gavin.downard@runbox.com>
To: Max Nikulin <manikulin@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] lisp/org-table.el: Allow named columns on lhs
Date: Sat, 22 Jul 2023 11:21:59 -0700	[thread overview]
Message-ID: <87bkg3hga5.fsf@runbox.com> (raw)
In-Reply-To: <e776ec59-a406-a77e-cd2b-a2a00889eecc@gmail.com>

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.


  reply	other threads:[~2023-07-22 20:02 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-19  2:36 [PATCH] lisp/org-table.el: Allow named columns on lhs Gavin Downard
2023-07-19  7:44 ` Ihor Radchenko
2023-07-21 15:15   ` Max Nikulin
2023-07-21 18:33     ` Gavin Downard
2023-07-22  2:12       ` Max Nikulin
2023-07-22  7:25         ` Ihor Radchenko
2023-07-22 13:16           ` Max Nikulin
2023-07-22 13:25             ` Ihor Radchenko
2023-07-22 12:45 ` Max Nikulin
2023-07-22 18:21   ` Gavin Downard [this message]
2023-07-23  6:50     ` Ihor Radchenko
2023-07-24  3:25       ` Gavin Downard
2023-07-24  7:23         ` Ihor Radchenko
2023-07-24 15:17 ` Max Nikulin
2023-07-24 20:29   ` Gavin Downard
2023-07-25 15:01     ` Max Nikulin
2023-07-26 21:50       ` Gavin Downard
2023-07-27  7:36         ` Ihor Radchenko
2023-08-29  9:58 ` Ihor Radchenko
2023-08-31 14:19   ` Gavin Downard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bkg3hga5.fsf@runbox.com \
    --to=gavin.downard@runbox.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=manikulin@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).