[Pmwiki-users] Suggestions for [[<<]] replacement.

Christian Ridderström chr
Wed Jan 14 08:10:06 CST 2004


On Wed, 7 Jan 2004, Patrick R. Michaud wrote:

> On Mon, Jan 05, 2004 at 04:30:41AM +0100, Christian Ridderstr?m wrote:
> > It's probably a good idea to look at how [[<<]] is used today. I did a
> > simple check on how often it is used in 'my' site:
> > 	wiki.d$ ls -1 | wc --lines
> >             393
> > 	wiki.d$ grep -l '\[\[<<]]' * | wc --lines
> > 	    98
> > where it's used in roughly 25% of the pages. However, the files aren't in
> > raw form... is there a way I could 'unscramble' them?
> 
> Sure, use grep(1) and take out only the lines that begin with "text=".
> E.g., something like:
> 
>    grep '^text=' * | grep -l '\[\[<<]]' | wc --lines
> 
> or, to avoid the extra grep:
> 
>    grep '^test=.*\[\[<<]]' * | wc --lines
> 
> Pm

 
Thanks. How can I extract the text with line breaks etc?
(not using ?action=source, but through raw access to the file).

I've also attached a small utility I wrote in Emacs lisp for checking the
n:o occurences of different kinds of markup.

A simple way to use it is as follows:

  emacs -l count-markup.el --eval '(count-markup "~/pmwiki/wiki.d/")'
  
assuming your pmwiki-directory is '~/pmwiki' (i.e. the pages are stored in 
files in the directories '~/pmwiki/wiki.d/' and '~/pmwiki/wikilib.d/')

The result of running thsi script for wiki.lyx.org looks like this:

	The contents of the pmwiki-pages are in *pmwiki-pages*.
	Page data was loaded from
		~/pmwiki/wiki.d
	and
		~/pmwiki/wikilib.d

	The total n:o of pages is 466

	String          Occ.          Actual regexp
	'@@'            1896            '@@'
	'[['            2044            '\[\['
	'@@['           297             '@@\['
	'@@[='          240             '@@\[='
	'@@[-'          41              '@@\[-'
	'@@[['          15              '@@\[\['

and it's easy to have it check for other regexps. 

/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-directory dir)
  (let ((cur-buf (current-buffer)))
    (set-buffer pmwiki-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)))
    (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 "%-15s %-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
     '("@@" "\\[\\[" 
       "@@\\[" "@@\\[=" "@@\\[-" "@@\\[\\["))

(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