forcemerge 454778 117564
thanks

On Mon, Mar 03, 2008 at 04:35:06PM +0100, Agustin Martin wrote:
> On Fri, Feb 29, 2008 at 05:35:56PM +0100, Agustin Martin wrote:
> > I finally noticed *where the bug really is*, in
> > debian-startup.el->(debian-run-directories) function, after reading the
> > /etc/emacs/site-start.d stuff, rearranges the load path and puts
> > site-lisp stuff first in the load-path, what is plain wrong.
> > 
> > Will try to look better into this bug.
> 
> Tried a bit harder and wrote a proof of concept, also including other
> changes. Note that this is written for xemacs21 or emacs21 or higher (I
> think this will work with all xemacs21 versions, but I might be wrong). It
> will not work for ancient emacs19 or emacs20. If is important to have
> emacsen-common support for them, I can try to use the old (while..) instead
> of dolist and define a better add-to-list (emacs20 definition is
> incompatible). Otherwise conflicts are needed.

Hi all,

Played a bit more and did a major rewrite of the (debian-run-directories)
function to a way I find easier to read. Also removed the local check,
xemacs seems to not explicitly set local directories.

Attached the final result in case you find it useful. Note that as for
the previous one, will not work for ancient emacs19 or emacs20 (did not
look at xemacs20, but might fail too).

Also noticed that this bug report is the same as #454778. Patch provided
there will also not work for ancient emacs (dolist not present), but if you
really want to have emacsen-common work for ancient stuff the #454778 patch
is easier to adapt. Since both bugs are the same, I am forcemerging them.

-- 
Agustin
;;; debian-startup.el --- Debian specific emacsen startup code.

;; Copyright (C) 1998 Rob Browning

;; Maintainer: Rob Browning <[EMAIL PROTECTED]>
;; Keywords: debian

;; This file is part of the debian release of GNU Emacs, and will
;; be contributed to the FSF after testing. It is released under the same
;; terms, namely the GPL v2 or later.

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;; This file contains startup code needed by all the various flavors
;; of Emacs for a Debian system.


(defun debian-sanitized-emacs-load-path ( &optional exclude )
  "Make sure ``load-path'' has the right ordering, returning it.
If optional list EXCLUDE is given, will take its elements out
of ``load-path''"
  (let (etc-load-path
        local-load-path
        site-load-path
        system-load-path)
    (dolist (path load-path)
      (or (member path exclude)
          (if (string-match "^/usr/local" path)
              (add-to-list 'local-load-path path t)
            (if (string-match "^/etc" path)
                (add-to-list 'etc-load-path path t)
              (if (string-match "/site-lisp" path)
                  (add-to-list 'site-load-path path t)
                (add-to-list 'system-load-path path t))))))
    (or local-load-path
        (error "No /usr/local/ prefixed paths in load-path"))
    (append etc-load-path
            local-load-path
            site-load-path
            system-load-path)))

(defun debian-pkg-add-load-path-item (item)
  "Takes a path item (a string) and adds it to load path in the
correct position for an add-on package, before the emacs system
directories, but after the /usr/local/ directories.  After modifying
load-path, returns the new load-path."
  (add-to-list 'load-path item)
  (setq load-path (debian-sanitized-emacs-load-path))
  load-path)

(defun debian-run-directories (&rest dirs)
  "Load each file of the form XXfilename.el or XXfilename.elc in any
of the dirs, where XX must be a number.  The files will be run in
alphabetical order.  If a file appears in more than one of the dirs,
then the earlier dir takes precedence, and a .elc file always
supercedes a .el file of the same name."
  (let (site-files  ;; List of site start files (no dir prefix, no extension)
        extra-dirs) ;; site-start-dirs not currently in ``load-path''

    ;; Get list of site start files
    (dolist (dir dirs)
      (dolist (file (directory-files dir nil "^[0-9][0-9].*\\.\\(el\\|elc\\)$" 
t))
        (string-match "\\.\\(el\\|elc\\)$" file)
        (add-to-list 'site-files (replace-match "" t t file ))))

    ;; Get list of site-start-dirs not currently in ``load-path''
    (dolist (dir dirs)
      (or (member dir load-path)
          (add-to-list 'extra-dirs dir)))

    ;; Put site-start-dirs in ``load-path'' and actually load site start files.
    (setq load-path (append extra-dirs load-path))
    (dolist (file (sort site-files 'string<))
      (condition-case ()
          (load file)
        (error (message "Error while loading %s" file))))

    ;; Sanitize load-path. Re-order if needed and remove temporal additions
    (setq load-path (debian-sanitized-emacs-load-path extra-dirs))))

(defun debian-startup (flavor)
  ;; Our handling of debian-emacs-flavor here is truly weird, but we
  ;; have to do it like this because some of the emacsen flavors
  ;; didn't DWIM in their startup sequence.  I wasn't as clear as I
  ;; should have been in debian-policy, but they were also
  ;; technically violating policy.

  ;; It's even weirder now.  I've changed policy back to the old way,
  ;; but I'm also doing some sanity checking here and making sure that
  ;; even debian-emacs-flavor gets set no matter what.  I'm in a rush
  ;; right now, but I'll come back later and make all this cleaner and
  ;; better documented.  Sorry.

  (or (boundp 'debian-emacs-flavor)
      (defconst debian-emacs-flavor flavor
        "A symbol representing the particular debian flavor of emacs that's
running.  Something like 'emacs20, 'xemacs20, etc."))

  (let ((common-dir "/etc/emacs/site-start.d")
        (flavor-dir (concat "/etc/" (symbol-name flavor) "/site-start.d")))
    (debian-run-directories flavor-dir common-dir)))

Reply via email to