From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: elisp code takes CPU too much Date: Mon, 27 Dec 2010 07:17:48 -0700 Message-ID: <87r5d3i7q3.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from [140.186.70.92] (port=37560 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PXEWA-0007Kj-2t for emacs-orgmode@gnu.org; Mon, 27 Dec 2010 09:57:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PXEW8-0004zR-VH for emacs-orgmode@gnu.org; Mon, 27 Dec 2010 09:57:45 -0500 Received: from mail-qw0-f41.google.com ([209.85.216.41]:62269) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PXEW8-0004zE-Sv for emacs-orgmode@gnu.org; Mon, 27 Dec 2010 09:57:44 -0500 Received: by qwa26 with SMTP id 26so8322872qwa.0 for ; Mon, 27 Dec 2010 06:57:44 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: ishi soichi Cc: emacs-orgmode@gnu.org My only guess would be repeatedly calling the `org-table-put' function from inside of your inner while loop. Specifically including the ALIGN option to the function is repeatedly re-aligning your table. Maybe performance would be improved by calling `org-table-align' once after the end of your while loop, rather than in every loop execution. Also, as a style point I would recommend using `map' rather than while to iterate through the elements of the word-list. For an additional performance gain, you may want to remove the call to `org-table-put' altogether, and instead simply insert the word directly and then manually adjust the location of `point' in the buffer. Hope this helps -- Eric ishi soichi writes: > hi. I have wrote an elisp code for org-mode, which puts entries in a table. > It is a simple code in my opinion and it does the job I intended. But when > executed, the activation of CPU shoots up and it will take a while to > complete it. I do not believe that this little code requires such a > work-load for the computer. There must be my wrong-doing. > > Could anyone help me for fixing it? > > soichi > > P.S. the code follows, and there is "word" in the table so that "search" > command looks for it. > ;;--------------------------------------------- > (require 'org-table) > (setq alist (list "apple" "orange" "lemon" "baseball" "football")) > (defun test-table (word-list) > "test to see if org-table-put works well" > (find-file-noselect (concat "~/Dropbox/language/word.org")) > (set-buffer "word.org") > (save-excursion > (goto-char (point-min)) > (search-forward "word") > (goto-char (match-beginning 0)) > (let ((i 1)) > (while word-list > (org-table-put i 3 (nth (- i 1) word-list) t) > (setq i (1+ i)))))) > > (test-table alist) ;;execute it here > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode