help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Visitor here is a gedit user; how to interest him in Emacs?


From: Pascal J. Bourguignon
Subject: Re: Visitor here is a gedit user; how to interest him in Emacs?
Date: Wed, 08 Dec 2010 15:23:07 -0000
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/23.2 (gnu/linux)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]