It’s already been one year since I switched from Vim to Emacs (thanks Aleksander;) I heard a lot about how powerful the Elisp is, but I didn’t have much motivation in learning it. I started playing with Elisp last weekend and I must say that is much different from everything I used before. Anyway because I work a lot with GObjects and Glib I decided to create some useful script which will speed up my coding. My first script is trivial but it helps to create GList iterator, it acts as a simple code snippet with this difference, that the initial position of the iterator is assigned with the identifier under the cursor.

Elisp script:

(defun azt-glist-iterate-all()
    "Creates a GList iterator for
      the list under the cursor"
    (setq itr_template "GList *node_itr = vvv;
while (node_itr != NULL)
    /* GType *data = (GType *)node_itr->data; */
    node_itr = g_list_next(node_itr);
    ; Replace patter with a word at point
    (setq initializer
             (replace-regexp-in-string "\*" "" 
                   (thing-at-point 'symbol)))
    (setq itr_template 
             (replace-regexp-in-string "vvv" 
                     initializer itr_template))
    (forward-line 1)
    (insert itr_template)

When the script is loaded into Emacs and you start typing something like “GList *my_list = priv->_list” , put your cursor on my_list identifier and M-x azt-glist-iterate-all you will generate the snipper below:

GList *node_itr = my_list;
while (node_itr != NULL)
    /* GType *data = (GType *)node_itr->data; */
    node_itr = g_list_next(node_itr);
Blog Entry
, ,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>