[Pmwiki-users] Suggestions for [[<<]] replacement.
Christian Ridderström
chr
Wed Jan 14 10:07:34 CST 2004
On Wed, 14 Jan 2004, Patrick R. Michaud wrote:
> On Wed, Jan 14, 2004 at 04:09:55PM +0100, Christian Ridderstr?m wrote:
> > > Sure, use grep(1) and take out only the lines that begin with "text=".
> > > E.g., something like:
> > > grep '^text=' * | grep -l '\[\[<<]]' | wc --lines
> >
> > Thanks. How can I extract the text with line breaks etc?
> > (not using ?action=source, but through raw access to the file).
>
> grep -h '^text=' [file] | tr '\262' '\012'
Thanks. Attached is a modified 'count-markup.el' that now can be used to
look for regexps such as '^: :'.
/Christian
--
Dr. Christian Ridderstr?m, +46-8-768 39 44 http://www.md.kth.se/~chr
-------------- next part --------------
;;
;; Instructions:
;;
;; Alternative 1:
;; 1) Modify the function `insert-number-of-matches' below to print the
;; statistics you are interested in.
;;
;; 2) Do 'M-x load-file' on this file (if you haven't before)
;;
;; 3) Run 'M-x load-pmwiki-pages' to setup a buffer with all pmwiki pages
;;
;; 4) Run 'M-x insert-markup-count' to create table with n:o matches.
;; The table will be inserted in the current buffer.
;;
;; Alternative 2:
;; - Run 'M-x load-file' on this file.
;; - Run 'M-x count-markup' to do step 3 and 4 of alt. 1 in one go.
;;
;; Alternative 3:
;; Start emacs with the follwing command-line:
;; emacs -l count-markup.el \
;; --eval '(count-markup "~/pmwiki")'
;;
(defun load-pmwiki-pages (dir)
"Load all data of all pmwiki-pages into a buffer, where the
name of the buffer will be stored in `pmwiki-pages-buffer'."
(interactive "DDirectory of pmwiki-pages [Ex: /home/chr/pmwiki] ")
(set 'pmwiki-pages-buffer (generate-new-buffer "*pmwiki-pages*"))
(set 'pmwiki-raw-pages-buffer (generate-new-buffer "*pmwiki-raw-pages*"))
(set 'pmwiki-directory dir)
(let ((cur-buf (current-buffer)))
(set-buffer pmwiki-raw-pages-buffer)
(insert (shell-command-to-string
(concat "grep '^text=' " dir "/wiki.d/*")))
(insert (shell-command-to-string
(concat "grep '^text=' " dir "/wikilib.d/*")))
(goto-char (point-min))
(toggle-truncate-lines)
(set 'pmwiki-page-count (count-lines (point-min) (point-max)))
(goto-char (point-min))
(replace-regexp "?" "")
(goto-char (point-min))
(set-buffer pmwiki-pages-buffer)
(insert (shell-command-to-string
(concat "grep '^text=' " dir "/wiki.d/* | tr '\262' '\012'")))
(insert (shell-command-to-string
(concat "grep '^text=' " dir "/wikilib.d/* | tr '\262' '\012'")))
(goto-char (point-min))
(replace-regexp "^\\(.+\\):text="
"\n----------------- \\1 -----------------\n" )
(goto-char (point-min))
(set-buffer cur-buf)))
(defun count-matches-in-pmwiki-pages (re)
"Return the n:o matches of the regular expression RE
in the buffer specified by `pmwiki-pages-buffer'"
(save-excursion
(set-buffer pmwiki-pages-buffer)
(goto-char (point-min))
(string-to-number (how-many re))))
(defun insert-number-of-matches-of-regexp (re)
"Count and insert the n:o of matches to RE
in the buffer specified by `pmwiki-pages-buffer'"
(interactive "sRegular expression:")
(let ((fmt "%-25s %-5d '%s'\n"))
(insert (format fmt
(format "'%s'" (replace-regexp-in-string "\\\\" "" re))
(count-matches-in-pmwiki-pages re)
re
))))
;(set 'pmwiki-pages-buffer (extract-pmwiki-pages))
;(message (format "Data from the pmwiki-pages are in %s" pmwiki-pages-buffer))
(set 'pmwiki-markup-regexps
'("@@"
"\\[\\["
"@@\\["
"@@\\[="
"@@\\[-"
"@@\\[\\["
"^ .+[^ ]" ; PRE-environment
"^![^!]" ; Header 1
"^!![^!]" ; Header 2
"^!!![^!]" ; Header 3
"^!!!![^!]" ; Header 4
))
(defun insert-markup-count ()
"Show statistics for regular expressions in `pmwiki-markup-regexps'"
(interactive)
(insert (format "\nThe contents of the pmwiki-pages are in %s.\n"
pmwiki-pages-buffer))
(insert (format
"Page data was loaded from\n\t%s/wiki.d\nand\n\t%s/wikilib.d\n\n"
pmwiki-directory pmwiki-directory))
(insert (format "The total n:o of pages is %d\n\n" pmwiki-page-count))
(insert "String Occ. Actual regexp\n")
(dolist (re pmwiki-markup-regexps) (insert-number-of-matches-of-regexp re))
)
(defun count-markup (dir)
"Load all data of all pmwiki-pages into a buffer, where the
name of the buffer will be stored in `pmwiki-pages-buffer'.
Once the pmwiki-pages have been loaded, run `insert-number-matches'."
(interactive "DDirectory of pmwiki-pages [Ex: /home/chr/pmwiki/wiki.d] ")
(load-pmwiki-pages dir)
(insert-markup-count))
More information about the pmwiki-users
mailing list