From mboxrd@z Thu Jan 1 00:00:00 1970 From: Torsten Wagner Subject: Re: Problem: Moving rows in a table changes vsum start and end Date: Sat, 29 Sep 2012 01:17:23 +0900 Message-ID: References: <87k3veilfz.fsf@bzg.ath.cx> <877greuud7.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:55983) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THdH5-0007zU-8f for emacs-orgmode@gnu.org; Fri, 28 Sep 2012 12:19:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1THdFm-0004sw-KG for emacs-orgmode@gnu.org; Fri, 28 Sep 2012 12:18:46 -0400 Received: from mail-we0-f169.google.com ([74.125.82.169]:63535) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THdFl-0004qm-6w for emacs-orgmode@gnu.org; Fri, 28 Sep 2012 12:17:25 -0400 Received: by weyu3 with SMTP id u3so1698648wey.0 for ; Fri, 28 Sep 2012 09:17:23 -0700 (PDT) In-Reply-To: <877greuud7.fsf@bzg.ath.cx> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Bastien Cc: Org Mode Mailing List Hi Bastien, ok, I think it should be in org-table.el and the function in question might be org-table-fix-formulas I added (defface org-table-formular-change-face '((t (:background "red"))) "Used parts of tabe formulars which change by row and column moving operations.") to define a new face for changes in the formular. Then I looked around how to do the face changing. By that I noticed, org-mode uses its own set of functions (org-table-highlight-rectangle, org-table-remove-rectangle-highlight). Searching more around I figured out that emacs already comes with a function for highlighting. http://www.gnu.org/software/emacs/manual/html_node/emacs/Highlight-Interactively.html#Highlight-Interactively Which makes me wonder why org-mode don't use that (maybe historical reasons, the above function is not that old). >From this there are mainly two functions of interest highlight-regexp unhighlight-regexp (btw. a not very emacs conform naming) they take a regular expression as input and optional the face to be set. It works great in interactive mode. So I was looking how to modify the function org-table-fix-formulas using the above commands I ended up with a very small change (defun org-table-fix-formulas (key replace &optional limit delta remove) "Modify the equations after the table structure has been edited. KEY is \"@\" or \"$\". REPLACE is an alist of numbers to replace. For all numbers larger than LIMIT, shift them by DELTA." (save-excursion (goto-char (org-table-end)) (when (let ((case-fold-search t)) (looking-at "[ \t]*#\\+tblfm:")) (let ((re (concat key "\\([0-9]+\\)")) (re2 (when remove (if (or (equal key "$") (equal key "$LR")) (format "\\(@[0-9]+\\)?%s%d=.*?\\(::\\|$\\)" (regexp-quote key) remove) (format "@%d\\$[0-9]+=.*?\\(::\\|$\\)" remove)))) s n a) (when remove (while (re-search-forward re2 (point-at-eol) t) (unless (save-match-data (org-in-regexp "remote([^)]+?)")) (if (equal (char-before (match-beginning 0)) ?.) (error "Change makes TBLFM term %s invalid. Use undo to recover." (match-string 0)) (replace-match ""))))) (while (re-search-forward re (point-at-eol) t) (unless (save-match-data (org-in-regexp "remote([^)]+?)")) (setq s (match-string 1) n (string-to-number s)) (cond ((setq a (assoc s replace)) (replace-match (concat key (cdr a)) t t)) ((and limit (> n limit)) (replace-match (concat key (int-to-string (+ n delta))) t t))) ;Added the single line below (highlight-regexp re 'org-table-formular-change-face) ; really only the above line )))))) However, it does not work. Defining the face and using the above line works correct in the scratch buffer, However, calling the function within org-mode (moving rows in a table) I do not get an error message and do not get a highlight... I made sure my modified version but no luck yet. I greatly lack elisp knowledge, would be glad if you could give me some advice why it doesn't work. Furthermore, you might like to check about the highlight functions. You might be able to simplify some of the org-table.el code by relying on those functions instead of defining own functions. If we get this started, I dream of slightly different face different parts of org-tables: * cells base on a formula and not been updated, despite changes were made in the table, * cells base on a formula but good overwritten by the user (this is another dangerous situation I found myself in) * highlight the formulas for the cell in which the pointer is located (kind of reveres of the current fomular editor highlighting) * highlight changes after recalculation of an table As for the last point. I also found the minor mode "highlight-changes-mode" This is a great mode and calling it before starting to manipulate a org-table, already ticks some of the above points. Please try if you are not aware of it (create a table with some forms, call highlight-changes-mode, do some operations on the table). Greetings Torsten On 28 September 2012 22:53, Bastien wrote: > Hi Torsten, > > Torsten Wagner writes: > >> everytime you do this, I feel more embarrassed about my poor elisp knowledge. ;) >> I might start very very simple and hope you are wiling enough to help >> me to translate whatever mess I send you into some reasonable patch ;) > > Sure! Actually I was not point at *you* in particular, "patch welcome" > just means "if someone wants to put a stab, please feel free..." > > But thanks in advance if _you_ help with this! > > -- > Bastien