all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: Visitor here is a gedit user; how to interest him in Emacs?
Date: Thu, 05 Aug 2010 14:57:00 +0200	[thread overview]
Message-ID: <877hk5w737.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: i3drea$qh$1@news.onet.pl

Marc Mientki <mientki@nonet.com> writes:

> Am 05.08.2010 08:12, schrieb David Combs:
>
>> every time I try to show him some Emacs concep, he says
>> that he can do that in gedit also.
>
> Another example. Let him convert that
>
>   value_at_1_4 = 10;
>   value_at_2_2 = 11;
>   value_at_5_1 = 300;
>
> to this:
>
>   value[3][0] = 10;
>   value[1][1] = 11;
>   value[0][4] = 300;

> So he should extract two last number parts from variable name, remove
> _at_' from name, use both index for c-array-indexing but in reverse
> order and 0-based (original was 1-based). Of course everything in one
> pass in full automatic :-)

Even better:

/*

matrix is:
    | 2  9 11 | 
    | 6  5  0 |
    | 1 12  7 |
    
*/

and have it transform this comment into the matrix intialization code:

matrix[1][1]=2;
matrix[1][2]=6;
matrix[1][3]=1;
matrix[2][1]=9;
matrix[2][2]=5;
matrix[2][3]=12;
matrix[3][1]=11;
matrix[3][2]=0;
matrix[3][3]=7;






(defun matrix-to-c (start end)
   (interactive "r")
   (goto-char start)
   (when (re-search-forward "\\([_A-Za-z][_A-Za-z0-9]*\\)  *is *:" end t)
     (let ((name (match-string 1))
           (data '()))
       (while (re-search-forward "|\\(.*\\)|" end t)
           (push (first (read-from-string (concat "(" (match-string 1) ")"))) data))
       (setf data (reverse data))
       (search-forward "*/")
       (goto-char (match-end 0))
       (insert "\n")
       (loop
          for j from 1 to (length data)
          do (loop
                for i from 1 to (length (first data))
                do (insert (format "%s[%s][%s]=%s;\n" name j i (elt (elt data (1- i)) (1- j)))))))))

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/


  reply	other threads:[~2010-08-05 12:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-05  6:12 Visitor here is a gedit user; how to interest him in Emacs? David Combs
2010-08-05  7:45 ` Elena
2010-08-05  7:50 ` Marc Mientki
2010-08-05 17:23   ` David Combs
2010-08-05 17:46     ` David Kastrup
2010-08-05  8:06 ` Marc Mientki
2010-08-05 12:57   ` Pascal J. Bourguignon [this message]
2010-08-05 14:46     ` Marc Mientki
2010-08-05  8:25 ` Elena
2010-08-05 14:55 ` despen
2010-08-06  5:49 ` TheFlyingDutchman

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

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

  git send-email \
    --in-reply-to=877hk5w737.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.