Posts

Showing posts with the label emacs

Map on lines in Emacs

;;;-------------------------------------------------------------------- (defun u:map-lines (beg end func) "Call given FUNC in the form (LAMBDA (LBEG LEND LSTR LCOUNT)...) for every line in the region. By default just print them." (interactive "r\nXMap Function ((LAMBDA (LSTR LBEG LEND LCOUNT) ...)): ") (let ((count 1) (inhibit-field-text-motion t)) (when (stringp func) (setq func (car (read (eval (concat "(" func ")")))))) (unless func (setq func #'(lambda (s b e c) (princ (format "%4d:%s" c s))))) (save-excursion (save-match-data (goto-char beg) (let (lbeg lend lstr (delta (- (point-max) end))) (while ( (setq lbeg (line-beginning-position 1)) (setq lend (line-beginning-position 2)) (setq lstr (buffer-substring-no-properties lbeg lend)) (funcall...

Loop on lines in emacs (version 1)

(defmacro do-lines (args &rest body) (let ((line (gensym "line-")) (beg (gensym "beg-")) (end (gensym "end-"))) `(let (,@args) (save-excursion (save-match-data (goto-char (point-min)) (while ( (setq ,beg (point)) (forward-line 1) (setq ,end (point)) (setq ,line (buffer-substring-no-properties ,beg ,end)) (setq ,(car args) ,line) (when ',(cdr args) (setq ,(cadr args) ,beg)) (when ',(cddr args) (setq ,(caddr args) ,end)) (progn ,@body))))))) (let (lines) (do-lines (l b e) (push (cons l e) lines)) (reverse lines))

Back To Etags

In my previous post I wrote about using exuberant-ctags for emacs and Objective-C. But for some reason exuberant-ctags failed to create tags for funcions in /usr/include/string.h on my Mac. So, I switched back to etags. Here the correspondent shell script for generating tags for system headers on Mac OS X: #!/bin/sh s="\t " S="[$s]*" w="_a-zA-Z0-9" CN="[A-Z][$w]*" NM="[$w][$w]*" ETAGS="/Applications/Emacs.app/Contents/MacOS/bin/etags" cat /dev/null > tmp.tags find /usr/include -name "*.h" -exec \ $ETAGS -a --declarations -o tmp.tags \ "{}" ";" mv tmp.tags include.tags cat /dev/null > tmp.tags find /System/Library/Frameworks -name "*.h" -exec \ $ETAGS -a --declarations -o tmp.tags \ -r "/$S[-+]$S(\($S$NM\)\{1,3\}$S\**$S)?$S\($NM\)$S[:;]/\2/" \ "{}" ";" sed "/^@class/d" tmp.tags > Frameworks.tags rm tmp.tags

Using Exuberant Ctags with Emacs And Objective-C

Below is a small script that generates Emacs tags files for the header files in /System/Library/Frameworks and /usr/include on Mac: #!/bin/sh s="\t " S="[$s]*" w="_a-zA-Z0-9" CN="[A-Z][$w]*" NM="[$w][$w]*" cat /dev/null > tmp.tags find /usr/include -name "*.h" -exec \ ctags -e -a -o tmp.tags "{}" ";" awk -v LINE="" ' { if (LINE != $0) {LINE = $0; print $0;} }' tmp.tags > include.tags cat /dev/null > tmp.tags find /System/Library/Frameworks -name "*.h" -exec \ ctags -e -a -o tmp.tags \ --regex-C++="/^@(interface|protocol)$S($CN($S\($CN\))*)/\2/c/" \ --regex-C++="/^$S(\-|\+)$S\($S$NM($S$NM)*$S\**$S\)*$S($NM)$S[:;]/\3/f/" \ "{}" ";" awk -v LINE="" ' { if (LINE != $0) {LINE = $0; print $0;} }' tmp.tags > Frameworks.tags rm tmp.tags