From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: [patch] Sort the sitemap again Date: Thu, 22 Apr 2010 15:16:23 +0200 Message-ID: References: <87wrw02ric.fsf@gmx.de> <43C32696-E65A-4337-A75C-3ECE447CE51F@gmail.com> <87fx2n21z7.fsf@gmx.de> Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O4wGc-0006kQ-PT for emacs-orgmode@gnu.org; Thu, 22 Apr 2010 09:16:30 -0400 Received: from [140.186.70.92] (port=33295 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O4wGa-0006ih-OY for emacs-orgmode@gnu.org; Thu, 22 Apr 2010 09:16:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O4wGZ-0002BM-4m for emacs-orgmode@gnu.org; Thu, 22 Apr 2010 09:16:28 -0400 Received: from mail-ww0-f41.google.com ([74.125.82.41]:42948) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O4wGY-0002B1-TR for emacs-orgmode@gnu.org; Thu, 22 Apr 2010 09:16:27 -0400 Received: by wwe15 with SMTP id 15so19332wwe.0 for ; Thu, 22 Apr 2010 06:16:26 -0700 (PDT) In-Reply-To: <87fx2n21z7.fsf@gmx.de> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Sebastian Rose Cc: Emacs-orgmode mailing list On Apr 22, 2010, at 12:52 PM, Sebastian Rose wrote: > > We'll have to use `equal' then, not `eq': No, you need to change your defintion of the publishing alist to use first and last instead of "first" and "last". This is Emacs Lisp, not Javascript :-) But you are right - my changes were incomplete, see below. > > > diff --git a/lisp/org-publish.el b/lisp/org-publish.el > index 496f4d1..34589db 100644 > --- a/lisp/org-publish.el > +++ b/lisp/org-publish.el > @@ -397,10 +397,10 @@ eventually alphabetically." > ;; a is directory, b not: > (cond > ((and (file-directory-p a) (not (file-directory-p b))) > - (setq retval (eq sitemap-sort-folders 'first))) > + (setq retval (equal sitemap-sort-folders 'first))) > ;; a is not a directory, but b is: > ((and (not (file-directory-p a)) (file-directory-p b)) > - (setq retval (eq sitemap-sort-folders 'last)))))) > + (setq retval (equal sitemap-sort-folders 'last)))))) > retval)) > > (defun org-publish-get-base-files-1 (base-dir &optional recurse > match skip-file skip-dir) > @@ -609,7 +609,7 @@ If :makeindex is set, also produce a file > theindex.org." > 'org-publish-org-sitemap)) > (sitemap-sort-folders > (if (plist-member project-plist :sitemap-sort-folders) > - (plist-get project-plist :sitemap-sort-folders) > + (plist-get project-plist :sitemap-sort-folders) > 'first)) > (sitemap-alphabetically > (if (plist-member project-plist :sitemap-alphabetically) > @@ -618,9 +618,9 @@ If :makeindex is set, also produce a file > theindex.org." > (preparation-function (plist-get project-plist :preparation- > function)) > (completion-function (plist-get project-plist :completion- > function)) > (files (org-publish-get-base-files project exclude-regexp)) > file) > - (when (and (not (stringp sitemap-sort-folders)) > - (not (string= sitemap-sort-folders "first")) > - (not (string= sitemap-sort-folders "last"))) > + (when (and (not (null sitemap-sort-folders)) > + (not (equal sitemap-sort-folders 'first)) > + (not (equal sitemap-sort-folders 'last))) Ah, ouch, indeed, here I failed miserably. Should be this: (unless (memq sitemap-sort-folders '(first last)) (setq sitemap-sort-folders nil)) Fixed now in git. - Carsten > (setq sitemap-sort-folders nil)) > (when preparation-function (run-hooks 'preparation-function)) > (if sitemap-p (funcall sitemap-function project sitemap- > filename)) > > >> - Minor changes to the docstring >> - Adding documentation to the manual > > Thanks! > >> Please check that I have not broken anything. > > Please apply the patch above - then it works again :) > Haarghh ... symbols... > > > > Sebastian > > >> >> Thanks, this is really a useful addition. >> >> - Carsten >> >>> >>> >>> >>> Best wishes >>> >>> Sebastian >>> >>> >>> >>> >>> diff --git a/lisp/org-publish.el b/lisp/org-publish.el >>> index 6ef1e24..a455997 100644 >>> --- a/lisp/org-publish.el >>> +++ b/lisp/org-publish.el >>> @@ -174,7 +174,17 @@ sitemap of files or summary page for a given >>> project. >>> of the titles of the files involved) or >>> `tree' (the directory structure of the >>> source >>> files is reflected in the sitemap). >>> Defaults to >>> - `tree'." >>> + `tree'. >>> + >>> + If you create a sitemap file, adjust the sorting like this: >>> + >>> + :sitemap-sort-folders Set this to one of \"first >>> \" (default), \"last\". >>> + Any other value will mixe files and >>> folders. >>> + :sitemap-alphabetically Set to `t' to sort filenames >>> alphabetically. >>> + Alphatical sorting is the default. >>> Hence you >>> + must set this to nil explecitly. >>> + :sitemap-ignore-case If non-nil, alphabetical sorting is done >>> + case-insensitive. Default: nil." >>> :group 'org-publish >>> :type 'alist) >>> >>> @@ -287,11 +297,16 @@ Each element of this alist is of the form: >>> (defvar org-publish-temp-files nil >>> "Temporary list of files to be published.") >>> >>> +;; Here, so you find the variable right before it's used the >>> first time: >>> +(defvar org-publish-file-title-cache nil >>> + "List of absolute filenames and titles.") >>> + >>> (defun org-publish-initialize-files-alist (&optional refresh) >>> "Set `org-publish-files-alist' if it is not set. >>> Also set it if the optional argument REFRESH is non-nil." >>> (interactive "P") >>> (when (or refresh (not org-publish-files-alist)) >>> + (setq org-publish-file-title-cache '()) >>> (setq org-publish-files-alist >>> (org-publish-get-files org-publish-project-alist)))) >>> >>> @@ -355,6 +370,32 @@ This splices all the components into the list." >>> (push p rtn))) >>> (nreverse (org-publish-delete-dups (delq nil rtn))))) >>> >>> +(defun org-publish-sort-directory-files (a b) >>> + "Predicate for `sort', that sorts folders-first/last and >>> +eventually alphabetically." >>> + (let ((retval t)) >>> + (when (or sitemap-alphabetically sitemap-sort-folders) >>> + ;; First we sort alphabetically: >>> + (when sitemap-alphabetically >>> + (let ((aorg (and (string-match "\\.org$" a) (not (file- >>> directory-p a)))) >>> + (borg (and (string-match "\\.org$" b) (not (file- >>> directory-p b))))) >>> + (setq retval >>> + (if sitemap-ignore-case >>> + (string-lessp (if borg (upcase (org-publish- >>> find-title a)) (upcase a)) >>> + (if aorg (upcase (org-publish- >>> find-title b)) (upcase b))) >>> + (string-lessp (if borg (org-publish-find-title >>> a) a) >>> + (if aorg (org-publish-find-title >>> b) b)))))) >>> + ;; Directory-wise wins: >>> + (when sitemap-sort-folders >>> + ;; a is directory, b not: >>> + (cond >>> + ((and (file-directory-p a) (not (file-directory-p b))) >>> + (setq retval (string= sitemap-sort-folders "first"))) >>> + ;; a is not a directory, but b is: >>> + ((and (not (file-directory-p a)) (file-directory-p b)) >>> + (setq retval (string= sitemap-sort-folders "last")))))) >>> + retval)) >>> + >>> (defun org-publish-get-base-files-1 (base-dir &optional recurse >>> match >>> skip-file skip-dir) >>> "Set `org-publish-temp-files' with files from BASE-DIR directory. >>> If RECURSE is non-nil, check BASE-DIR recursively. If MATCH is >>> @@ -374,7 +415,7 @@ matching the regexp SKIP-DIR when recursing >>> through >>> BASE-DIR." >>> (not (file-exists-p (file-truename f))) >>> (not (string-match match fnd))) >>> (pushnew f org-publish-temp-files))))) >>> - (directory-files base-dir t (unless recurse match)))) >>> + (sort (directory-files base-dir t (unless recurse match)) 'org- >>> publish-sort-directory-files))) >>> >>> (defun org-publish-get-base-files (project &optional exclude-regexp) >>> "Return a list of all files in PROJECT. >>> @@ -558,9 +599,18 @@ If :makeindex is set, also produce a file >>> theindex.org." >>> "sitemap.org")) >>> (sitemap-function (or (plist-get project-plist :sitemap-function) >>> 'org-publish-org-sitemap)) >>> + (sitemap-sort-folders (if (plist-member project- >>> plist :sitemap-sort-folders) >>> + (plist-get project-plist :sitemap- >>> sort-folders) "first")) >>> + (sitemap-alphabetically (if (plist-member project- >>> plist :sitemap-alphabetically) >>> + (plist-get project- >>> plist :sitemap- >>> alphabetically) t)) >>> + (sitemap-ignore-case (plist-get project-plist :sitemap- >>> ignore- >>> case)) >>> (preparation-function (plist-get project-plist :preparation- >>> function)) >>> (completion-function (plist-get project-plist :completion- >>> function)) >>> (files (org-publish-get-base-files project exclude-regexp)) file) >>> + (when (and (not (stringp sitemap-sort-folders)) >>> + (not (string= sitemap-sort-folders "first")) >>> + (not (string= sitemap-sort-folders "last"))) >>> + (setq sitemap-sort-folders nil)) >>> (when preparation-function (run-hooks 'preparation-function)) >>> (if sitemap-p (funcall sitemap-function project sitemap- >>> filename)) >>> (while (setq file (pop files)) >>> @@ -640,6 +690,8 @@ Default for SITEMAP-FILENAME is 'sitemap.org'." >>> >>> (defun org-publish-find-title (file) >>> "Find the title of file in project." >>> + (if (member file org-publish-file-title-cache) >>> + (cadr (member file org-publish-file-title-cache)) >>> (let* ((visiting (find-buffer-visiting file)) >>> (buffer (or visiting (find-file-noselect file))) >>> title) >>> @@ -654,7 +706,9 @@ Default for SITEMAP-FILENAME is 'sitemap.org'." >>> (file-name-nondirectory (file-name-sans-extension file)))))) >>> (unless visiting >>> (kill-buffer buffer)) >>> - title)) >>> + (setq org-publish-file-title-cache >>> + (append org-publish-file-title-cache (list file title))) >>> + title))) >>> >>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >>> ;;; Interactive publishing functions >>> >> >> - Carsten >> >> > > -- > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Sebastian Rose Fachinformatiker / Anwendungsentwicklung > Viktoriastr. 22 Entwicklung von Anwendungen mit freien Werkzeugen > 30451 Hannover und Bibliotheken. > > 0173 83 93 417 sebastian_rose@gmx.de s.rose@emma-stil.de > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Carsten