emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* elisp code takes CPU too much
@ 2010-12-27  5:47 ishi soichi
  2010-12-27 11:10 ` Jambunathan K
  2010-12-27 14:17 ` Eric Schulte
  0 siblings, 2 replies; 4+ messages in thread
From: ishi soichi @ 2010-12-27  5:47 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1042 bytes --]

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

[-- Attachment #1.2: Type: text/html, Size: 1636 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

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

* Re: elisp code takes CPU too much
  2010-12-27  5:47 elisp code takes CPU too much ishi soichi
@ 2010-12-27 11:10 ` Jambunathan K
  2010-12-29  8:51   ` Štěpán Němec
  2010-12-27 14:17 ` Eric Schulte
  1 sibling, 1 reply; 4+ messages in thread
From: Jambunathan K @ 2010-12-27 11:10 UTC (permalink / raw)
  To: ishi soichi; +Cc: emacs-orgmode


> 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.

You have an infinite loop. The predicate of the while loop would always
evaluate to 'true' and never become 'false'.

> Could anyone help me for fixing it?

Try the following snippet with suitable variations.

(setq word-list (list "apple" "orange" "lemon" "baseball" "football"))

(defun test-table (word-list) 
  (let ((line 0) (column 3))
    (mapcar (lambda (word)
	      (org-table-put i column word t))
	    word-list)))

Jambunathan K.


>
> 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

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

* Re: elisp code takes CPU too much
  2010-12-27  5:47 elisp code takes CPU too much ishi soichi
  2010-12-27 11:10 ` Jambunathan K
@ 2010-12-27 14:17 ` Eric Schulte
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Schulte @ 2010-12-27 14:17 UTC (permalink / raw)
  To: ishi soichi; +Cc: emacs-orgmode

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 <soichi777@gmail.com> 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

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

* Re: elisp code takes CPU too much
  2010-12-27 11:10 ` Jambunathan K
@ 2010-12-29  8:51   ` Štěpán Němec
  0 siblings, 0 replies; 4+ messages in thread
From: Štěpán Němec @ 2010-12-29  8:51 UTC (permalink / raw)
  To: Jambunathan K; +Cc: emacs-orgmode, ishi soichi

Jambunathan K <kjambunathan@coextrix.com> 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.
>
> You have an infinite loop. The predicate of the while loop would always
> evaluate to 'true' and never become 'false'.
>
>> Could anyone help me for fixing it?
>
> Try the following snippet with suitable variations.
>
> (setq word-list (list "apple" "orange" "lemon" "baseball" "football"))
>
> (defun test-table (word-list) 
>   (let ((line 0) (column 3))
>     (mapcar (lambda (word)
> 	      (org-table-put i column word t))
> 	    word-list)))

Unless you're going to do something with the list returned by this
function (seems unlikely given that `org-table-put' doesn't seem to
return anything useful), you should use `mapc' or `dolist' instead of
`mapcar'.

  Štěpán

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

end of thread, other threads:[~2010-12-29  8:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-27  5:47 elisp code takes CPU too much ishi soichi
2010-12-27 11:10 ` Jambunathan K
2010-12-29  8:51   ` Štěpán Němec
2010-12-27 14:17 ` Eric Schulte

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).