Emacs: printf skeleton

master
Pierre Neidhardt 2014-02-11 00:45:27 +01:00
parent 3d21d21757
commit 1cb803c4dc
2 changed files with 33 additions and 0 deletions

View File

@ -353,3 +353,11 @@ end of line after an ' = ' separtor."
(insert " = " (calc-eval (buffer-substring-no-properties
(line-beginning-position) (line-end-position)))))
(defun count-occurences (regex string)
"Return number of times regex occurs in string."
(let ((start 0) (matches 0))
(while (string-match regex string start)
(setq start (match-end 0))
(setq matches (1+ matches)))
matches))

View File

@ -123,3 +123,28 @@ restored."
(add-to-list 'semantic-lex-c-preprocessor-symbol-file (concat qt4-base-dir "/Qt/qconfig.h"))
(add-to-list 'semantic-lex-c-preprocessor-symbol-file (concat qt4-base-dir "/Qt/qconfig-large.h"))
(add-to-list 'semantic-lex-c-preprocessor-symbol-file (concat qt4-base-dir "/Qt/qglobal.h")))))
;;==============================================================================
;; Skel
;;==============================================================================
;; TODO: elements: (setq skeleton-further-elements '((q "\"")))
;; TODO: print: simpler version?
;; TODO: same number of prompt than of %
(add-hook
'c++-mode-hook
(lambda ()
(define-skeleton snip-print
"fprintf/printf snippet
If no file descriptor is provided, switch do printf.
The format string is properly parsed (%% are not taken into account)." nil
'(setq v1 (skeleton-read "File desc: " "stdout"))
(if (string= v1 "") "printf (" (concat "fprintf (" v1 ", "))
"\"" (setq v1 (skeleton-read "Format string: " "%s\\n")) "\""
(if (not (string-match "\\([^%]\\|^\\)\\(%%\\)*%[^%]" v1)) ");" "" ) |
(nil ("Value: " ", " str) ");")
)
))