all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* What's the right way to define a custom info path.
       [not found] <1139248550.294947690.1448466260727.JavaMail.root@spooler5n-g27.priv.proxad.net>
@ 2015-11-25 15:45 ` pierre.techoueyres
  2015-11-25 18:02   ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: pierre.techoueyres @ 2015-11-25 15:45 UTC (permalink / raw)
  To: help-gnu-emacs

** The context
   - I'm working on Windows 7 (but I think the Windows version is not important) with Emacs 24.5.1.
   - My Emacs is installed on c:/programmes/emacs (c:/programmes is a custom directory, not the standard Program Files which contains spaces).
   - I installed some packages with package.el :
     - org-plus-contrib
     - ecb

   - I extracted some packages from git versions on ~/.emacs.d/site-lisp :
     - tramp
     - cedet

   All packages have info files.

** My attempts
   I tried to setup everything properly to have Info display the right version of all manuals :
   - tramp in c:/programmes/emacs/share/emacs/24.5.50/lisp/net/ is superseded by the one in ~/.emacs.d/site-lisp/emacs-tramp an the info manual retrieved is the right one.
   - cedet in ~/.emacs.d/site-lisp/cedet is loaded before the one in c:/programmes/emacs an so on for the info manual
   - packages cedet superseded the one in emacs-core and Info display the latest manual

** what I've in my init.el

   First I've disabled autoexec of package initialize with `(setq package-enable-at-startup nil)' (this is needed to allow loading of custom cedet).

   Then I've added tramp's install dir to my load-path.

   Then defined a custom-file to ~/.emacs.d/custom.el

   Then add to my load-path cedet install dir and load the cedet-devel-load file which initialize everything.

   Then call package-initialize, and *after* load my custom-file.

** My problems
   First I tried to setup the Info-path with the custom variable `Info-default-directory-list' but that doesn't work, because of package-activate-1 which call info-initialize so the customization of Info-default-directory-list is done too late. And worse it's not correctly initialized !!!


   Next I try using `Info-directory-list' but to do so I must require info and call info-initialize in my init.el and I prefer to avoid that.

   Then I looked at `Info-additional-directory-list' which has the same problem as `Info-default-directory-list'.

** What I think should be done.
   1) `Info-default-directory-list' should be correctly initialized for the emacs w32.
      1) To do that env.el should provide an `w32-substitute-env-vars' to allow replacement of %var% strings with the corresponding env vars.
      2) The defcustom of Info-default-directory-list should call (substitute-env-vars configure-info-directory) instead of configure-info-directory directly.      

   2) `package-activate-1' should not require info nor use `info-initialize'. Instead it should add info paths on `Info-default-directory-list' or `Info-additional-directory-list' (maybe the later).

** My questions
   Have I do something wrong with my config ? Should I set an INFOPATH env var with absolutes paths ?
   If the answer of the previous questions is : No, should I open bugs ?
   
   Sorry for the really long message and the poor english.

** Some patches
   #+BEGIN_SRC ediff
3 files changed, 46 insertions(+), 5 deletions(-)
lisp/emacs-lisp/package.el |  9 +++++----
lisp/info.el               |  2 +-
lisp/w32-fns.el            | 40 ++++++++++++++++++++++++++++++++++++++++

modified   lisp/emacs-lisp/package.el
@@ -690,10 +690,11 @@ package-activate-1
                       loaded-files-list))))
     ;; Add info node.
     (when (file-exists-p (expand-file-name "dir" pkg-dir))
-      ;; FIXME: not the friendliest, but simple.
-      (require 'info)
-      (info-initialize)
-      (push pkg-dir Info-directory-list))
+      (unless (member pkg-dir Info-default-directory-list)
+	(push pkg-dir Info-default-directory-list))
+      (when (and (bound-and-true-p Info-directory-list)
+		 (not (member pkg-dir Info-directory-list)))
+	(push pkg-dir Info-directory-list)))
     (push name package-activated-list)
     ;; Don't return nil.
     t))
modified   lisp/info.el
@@ -186,7 +186,7 @@ Info-default-directory-list
 	   (or (and (featurep 'ns)
 		    (let ((dir (expand-file-name "../info" data-directory)))
 		      (if (file-directory-p dir) dir)))
-	       configure-info-directory)))
+	       (substitute-env-vars configure-info-directory))))
 	 (prefixes
 	  ;; Directory trees in which to look for info subdirectories
 	  (prune-directory-list '("/usr/local/" "/usr/" "/opt/" "/")))
modified   lisp/w32-fns.el
@@ -340,4 +340,44 @@ w32-append-code-lines
   (delete-matching-lines "^$\\|^;")
   (save-buffers-kill-emacs t))
 
+\f
+;;;; Support for environment variables
+(defconst w32-env--substitute-vars-regexp
+  "%\\(?:\\(?1:[[:alnum:]_\-]+\\)%\\|%\\)")
+
+(defun w32-substitute-env-vars (string &optional when-undefined)
+  "Substitute environment variables referred to in STRING.
+`%FOO%' where FOO is an environment variable name means to substitute
+the value of that variable.  The variable name should be terminated
+with a character not a letter, digit or underscore; otherwise, enclose
+the entire variable name in braces.  For instance, in `ab%cd-x%',
+`%cd-x%' is treated as an environment variable.
+
+If WHEN-DEFINED is nil, references to undefined environment variables
+are replaced by the empty string; if it is a function, the function is called
+with the variable name as argument and should return the text with which
+to replace it or nil to leave it unchanged.
+If it is non-nil and not a function, references to undefined variables are
+left unchanged.
+
+Use `%%' to insert a single percent sign."
+  (let ((start 0))
+    (while (string-match w32-env--substitute-vars-regexp string start)
+      (cond ((match-beginning 1)
+	     (let* ((var (match-string 1 string))
+                    (value (getenv var)))
+               (if (and (null value)
+                        (if (functionp when-undefined)
+                            (null (setq value (funcall when-undefined var)))
+                          when-undefined))
+                   (setq start (match-end 0))
+                 (setq string (replace-match (or value "") t t string)
+                       start (+ (match-beginning 0) (length value))))))
+	    (t
+	     (setq string (replace-match "%" t t string)
+		   start (+ (match-beginning 0) 1)))))
+    string))
+
+(defalias 'substitute-env-vars 'w32-substitute-env-vars))
+
 ;;; w32-fns.el ends here
   #+END_SRC



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: What's the right way to define a custom info path.
  2015-11-25 15:45 ` What's the right way to define a custom info path pierre.techoueyres
@ 2015-11-25 18:02   ` Eli Zaretskii
  2015-11-25 19:54     ` Pierre Téchoueyres
  2015-11-25 19:54     ` Pierre Téchoueyres
  0 siblings, 2 replies; 6+ messages in thread
From: Eli Zaretskii @ 2015-11-25 18:02 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Wed, 25 Nov 2015 16:45:07 +0100 (CET)
> From: pierre.techoueyres@free.fr
> 
> ** My problems
>    First I tried to setup the Info-path with the custom variable `Info-default-directory-list' but that doesn't work, because of package-activate-1 which call info-initialize so the customization of Info-default-directory-list is done too late. And worse it's not correctly initialized !!!
> 
> 
>    Next I try using `Info-directory-list' but to do so I must require info and call info-initialize in my init.el and I prefer to avoid that.
> 
>    Then I looked at `Info-additional-directory-list' which has the same problem as `Info-default-directory-list'.
> 
> ** What I think should be done.
>    1) `Info-default-directory-list' should be correctly initialized for the emacs w32.
>       1) To do that env.el should provide an `w32-substitute-env-vars' to allow replacement of %var% strings with the corresponding env vars.
>       2) The defcustom of Info-default-directory-list should call (substitute-env-vars configure-info-directory) instead of configure-info-directory directly.      
> 
>    2) `package-activate-1' should not require info nor use `info-initialize'. Instead it should add info paths on `Info-default-directory-list' or `Info-additional-directory-list' (maybe the later).
> 
> ** My questions
>    Have I do something wrong with my config ? Should I set an INFOPATH env var with absolutes paths ?
>    If the answer of the previous questions is : No, should I open bugs ?

The way to set this up correctly is to define the INFOPATH environment
variable (outside Emacs) which mentions the directories with Info
files in the proper order.  The Emacs is supposed to automatically
pick up the directories from INFOPATH, and you should be able to read
your manuals without any further problems.

You are instead trying to futz with Emacs variables that are not
supposed to do that well.  I suggest to save yourself a lot of trouble
and go via INFOPATH.

> ** My questions
>    Have I do something wrong with my config ? Should I set an INFOPATH env var with absolutes paths ?

Yes to INFOPATH.

>    If the answer of the previous questions is : No, should I open bugs ?

No, there's no bug here, AFAICT.  If you want to set up
Info-directory-list or Info-additional-directory-list, you must load
info.elc first.  (But again, I don't recommend going that way.)



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: What's the right way to define a custom info path.
  2015-11-25 18:02   ` Eli Zaretskii
  2015-11-25 19:54     ` Pierre Téchoueyres
@ 2015-11-25 19:54     ` Pierre Téchoueyres
  2015-11-25 20:24       ` Eli Zaretskii
  1 sibling, 1 reply; 6+ messages in thread
From: Pierre Téchoueyres @ 2015-11-25 19:54 UTC (permalink / raw)
  To: help-gnu-emacs

First, thanks for the answer.
I note that the recommended way to setup info is to use INFOPATH.
But, just for my knowledge, I would ask you about one or two things below.

Eli Zaretskii wrote:

>> ...
>> ** My questions
>>    Have I do something wrong with my config ? Should I set an INFOPATH
>>    env var with absolutes paths ? If the answer of the previous questions
>>    is : No, should I open bugs ?
> 
> The way to set this up correctly is to define the INFOPATH environment
> variable (outside Emacs) which mentions the directories with Info
> files in the proper order.  The Emacs is supposed to automatically
> pick up the directories from INFOPATH, and you should be able to read
> your manuals without any further problems.
> 
> You are instead trying to futz with Emacs variables that are not
> supposed to do that well.  I suggest to save yourself a lot of trouble
> and go via INFOPATH.
> 
>> ** My questions
>>    Have I do something wrong with my config ? Should I set an INFOPATH
>>    env var with absolutes paths ?
> 
> Yes to INFOPATH.
> 
>>    If the answer of the previous questions is : No, should I open bugs ?
> 
> No, there's no bug here, AFAICT.  If you want to set up
> Info-directory-list or Info-additional-directory-list, you must load
> info.elc first.  (But again, I don't recommend going that way.)

But these two variables could be modified with the custom machinery, and so 
without requiring info[.elc] aren't they ? But I understand your advice that 
doing that is discouraged.

Second, the default value for Info-default-directory-list (as computed by 
the defcustom in info.el) is ("%emacs_dir/info") on my windows install. Is 
this the expected behaviour ? this value is obviously overridden by info-
initialize and become, in my install, ("c:/programmes/emacs/info").
Again is this the expected behaviour ?

Third, in the windows patform (substitute-env-vars "%emacs_dir%") doesn't 
produce "c:/programmes/emacs" as I expected. But (substitute-env-vars 
"$emacs_dir") do the expansion. Is this the expected behaviour ? Is it that 
we should not offer a version that performs primary processing ?

Thanks agin for your answers.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: What's the right way to define a custom info path.
  2015-11-25 18:02   ` Eli Zaretskii
@ 2015-11-25 19:54     ` Pierre Téchoueyres
  2015-11-25 19:54     ` Pierre Téchoueyres
  1 sibling, 0 replies; 6+ messages in thread
From: Pierre Téchoueyres @ 2015-11-25 19:54 UTC (permalink / raw)
  To: help-gnu-emacs

First, thanks for the answer.
I note that the recommended way to setup info is to use INFOPATH.
But, just for my knowledge, I would ask you about one or two things below.

Eli Zaretskii wrote:

>> ...
>> ** My questions
>>    Have I do something wrong with my config ? Should I set an INFOPATH
>>    env var with absolutes paths ? If the answer of the previous questions
>>    is : No, should I open bugs ?
> 
> The way to set this up correctly is to define the INFOPATH environment
> variable (outside Emacs) which mentions the directories with Info
> files in the proper order.  The Emacs is supposed to automatically
> pick up the directories from INFOPATH, and you should be able to read
> your manuals without any further problems.
> 
> You are instead trying to futz with Emacs variables that are not
> supposed to do that well.  I suggest to save yourself a lot of trouble
> and go via INFOPATH.
> 
>> ** My questions
>>    Have I do something wrong with my config ? Should I set an INFOPATH
>>    env var with absolutes paths ?
> 
> Yes to INFOPATH.
> 
>>    If the answer of the previous questions is : No, should I open bugs ?
> 
> No, there's no bug here, AFAICT.  If you want to set up
> Info-directory-list or Info-additional-directory-list, you must load
> info.elc first.  (But again, I don't recommend going that way.)

But these two variables could be modified with the custom machinery, and so 
without requiring info[.elc] aren't they ? But I understand your advice that 
doing that is discouraged.

Second, the default value for Info-default-directory-list (as computed by 
the defcustom in info.el) is ("%emacs_dir/info") on my windows install. Is 
this the expected behaviour ? this value is obviously overridden by info-
initialize and become, in my install, ("c:/programmes/emacs/info").
Again is this the expected behaviour ?

Third, in the windows patform (substitute-env-vars "%emacs_dir%") doesn't 
produce "c:/programmes/emacs" as I expected. But (substitute-env-vars 
"$emacs_dir") do the expansion. Is this the expected behaviour ? Is it that 
we should not offer a version that performs primary processing ?

Thanks agin for your answers.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: What's the right way to define a custom info path.
  2015-11-25 19:54     ` Pierre Téchoueyres
@ 2015-11-25 20:24       ` Eli Zaretskii
  2015-11-25 22:13         ` Pierre Téchoueyres
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2015-11-25 20:24 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Pierre Téchoueyres <pierre.techoueyres@free.fr>
> Date: Wed, 25 Nov 2015 20:54:25 +0100
> 
> > No, there's no bug here, AFAICT.  If you want to set up
> > Info-directory-list or Info-additional-directory-list, you must load
> > info.elc first.  (But again, I don't recommend going that way.)
> 
> But these two variables could be modified with the custom machinery, and so 
> without requiring info[.elc] aren't they ?

Yes, you could do that.  But I interpreted your message as a request
to set them up in Lisp, not via Custom.

> But I understand your advice that doing that is discouraged.

No, it's not discouraged.  It just is harder to set up correctly,
whereas the semantics of INFOPATH is simple.

> Second, the default value for Info-default-directory-list (as computed by 
> the defcustom in info.el) is ("%emacs_dir/info") on my windows install. Is 
> this the expected behaviour ?

Yes.  That value is never used.

> this value is obviously overridden by info-
> initialize and become, in my install, ("c:/programmes/emacs/info").
> Again is this the expected behaviour ?

Yes.

> Third, in the windows patform (substitute-env-vars "%emacs_dir%") doesn't 
> produce "c:/programmes/emacs" as I expected. But (substitute-env-vars 
> "$emacs_dir") do the expansion. Is this the expected behaviour ?

Yes.  substitute-env-vars supports the Unix style of environment
variables.

> Is it that we should not offer a version that performs primary
> processing ?

We could, but why bother?  When info loads, it recomputes the value
according to where Emacs was installed.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: What's the right way to define a custom info path.
  2015-11-25 20:24       ` Eli Zaretskii
@ 2015-11-25 22:13         ` Pierre Téchoueyres
  0 siblings, 0 replies; 6+ messages in thread
From: Pierre Téchoueyres @ 2015-11-25 22:13 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii wrote:

>> From: Pierre Téchoueyres <pierre.techoueyres@free.fr>
>> Date: Wed, 25 Nov 2015 20:54:25 +0100
>> 
>> > No, there's no bug here, AFAICT.  If you want to set up
>> > Info-directory-list or Info-additional-directory-list, you must load
>> > info.elc first.  (But again, I don't recommend going that way.)
>> 
>> But these two variables could be modified with the custom machinery, and
>> so without requiring info[.elc] aren't they ?
> 
> Yes, you could do that.  But I interpreted your message as a request
> to set them up in Lisp, not via Custom.
> 
I've tried both aproaches. First with customize, but I found that package 
initialization discarded what I had set.
I expected that package init and customize have well worked together.

>> But I understand your advice that doing that is discouraged.
> 
> No, it's not discouraged.  It just is harder to set up correctly,
> whereas the semantics of INFOPATH is simple.
I'll try this tomorrow. But I guess I should set all info dir, even the ones 
installed by packages. I must check that.

> 
>> Second, the default value for Info-default-directory-list (as computed by
>> the defcustom in info.el) is ("%emacs_dir/info") on my windows install.
>> Is this the expected behaviour ?
> 
> Yes.  That value is never used.
> 
>> this value is obviously overridden by info-
>> initialize and become, in my install, ("c:/programmes/emacs/info").
>> Again is this the expected behaviour ?
> 
> Yes.
> 
>> Third, in the windows patform (substitute-env-vars "%emacs_dir%") doesn't
>> produce "c:/programmes/emacs" as I expected. But (substitute-env-vars
>> "$emacs_dir") do the expansion. Is this the expected behaviour ?
> 
> Yes.  substitute-env-vars supports the Unix style of environment
> variables.
> 
>> Is it that we should not offer a version that performs primary
>> processing ?
> 
> We could, but why bother?  When info loads, it recomputes the value
> according to where Emacs was installed.
To offer a substitute-env-vars with windows style ?




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-11-25 22:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1139248550.294947690.1448466260727.JavaMail.root@spooler5n-g27.priv.proxad.net>
2015-11-25 15:45 ` What's the right way to define a custom info path pierre.techoueyres
2015-11-25 18:02   ` Eli Zaretskii
2015-11-25 19:54     ` Pierre Téchoueyres
2015-11-25 19:54     ` Pierre Téchoueyres
2015-11-25 20:24       ` Eli Zaretskii
2015-11-25 22:13         ` Pierre Téchoueyres

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.