emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

building directory


From: Masatake YAMATO
Subject: building directory
Date: Fri, 04 Apr 2003 17:13:20 +0900 (JST)

Is there anyway to know in which directory the current running 
emacs was built?

I'd like to prepare an user interface to access emacs C source
files easily. M-x describe-function is very good entry point for
my goal.

For functions written in elisp, you can access its source easily
with M-x describe-function.

e.g. M-x describe-function gnus
---------------------------------------------------------
gnus is an interactive autoloaded Lisp function in `gnus'.
It is bound to <menu-bar> <tools> <gnus>.
(gnus &optional ARG DONT-CONNECT SLAVE)
-E:**--*Help*--------All-(4,0)----(Help View Abberv)-----

You can click `gnus' to show its emacs lisp source code.

But what happen if the target function is written in C?

e.g. M-x describe-function car
---------------------------------------------------------
car is a built-in function.
(car LIST)
-E:**--*Help*--------All-(4,0)----(Help View Abberv)-----

There is no pointer to the C source code. sigh.
I'd like to change the *Help* buffer for the built-in function
like:

---------------------------------------------------------
car is data.c in `data.c'.
(car LIST)
-E:**--*Help*--------All-(4,0)----(Help View Abberv)-----

So you can click data.c to read the definition of `car'.

I've tired to implement with using __FILE__ and __LINE__ cpp
predefined macro. However, __FILE__ shows just relative path,
not complete path. So I'd like to know the way to know in which 
directory current running Emacs was built.

Masatake YAMATO

Index: src/lisp.h
===================================================================
RCS file: /cvsroot/emacs/emacs/src/lisp.h,v
retrieving revision 1.449
diff -u -r1.449 lisp.h
--- src/lisp.h  23 Mar 2003 02:08:04 -0000      1.449
+++ src/lisp.h  4 Apr 2003 07:52:52 -0000
@@ -856,6 +856,8 @@
     char *symbol_name;
     char *prompt;
     char *doc;
+    const char *src_file;
+    short src_line;
   };
 
 
@@ -1611,9 +1613,9 @@
   Lisp_Object fnname ();                                               \
   struct Lisp_Subr sname =                                             \
     { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)),    \
-      fnname, minargs, maxargs, lname, prompt, 0};                     \
+      fnname, minargs, maxargs, lname, prompt, 0, __FILE__, (short)__LINE__}; \
   Lisp_Object fnname
-
+                                                                       
 #else
 
 /* This version of DEFUN declares a function prototype with the right
@@ -1622,7 +1624,7 @@
   Lisp_Object fnname DEFUN_ARGS_ ## maxargs ;                          \
   struct Lisp_Subr sname =                                             \
     { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)),    \
-      fnname, minargs, maxargs, lname, prompt, 0};                     \
+      fnname, minargs, maxargs, lname, prompt, 0, __FILE__, (short)__LINE__}; \
   Lisp_Object fnname
 
 /* Note that the weird token-substitution semantics of ANSI C makes
@@ -3003,6 +3005,8 @@
 /* defined in doc.c */
 extern Lisp_Object Vdoc_file_name;
 EXFUN (Fsubstitute_command_keys, 1);
+EXFUN (Fsource_line, 1);
+EXFUN (Fsource_file, 1);
 EXFUN (Fdocumentation, 2);
 EXFUN (Fdocumentation_property, 3);
 extern Lisp_Object read_doc_string P_ ((Lisp_Object));
Index: src/doc.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/doc.c,v
retrieving revision 1.99
diff -u -r1.99 doc.c
--- src/doc.c   4 Feb 2003 14:03:12 -0000       1.99
+++ src/doc.c   4 Apr 2003 07:52:52 -0000
@@ -360,6 +360,32 @@
   return 1;
 }
 
+DEFUN ("source-line", Fsource_line, Ssource_line, 1, 1, 0,
+       doc: /* The line number of the function definition in its source C 
file.  */)
+     (object)
+     Lisp_Object object;
+{
+  Lisp_Object fun;
+  fun = Findirect_function (object);
+  if (SUBRP (fun))
+    return make_number((EMACS_INT)XSUBR(fun)->src_line);
+  else
+    return Qnil;
+}
+
+DEFUN ("source-file", Fsource_file, Ssource_file, 1, 1, 0,
+       doc: /* The file name of the function definition of its source C file.  
*/)
+     (object)
+     Lisp_Object object;
+{
+  Lisp_Object fun;
+  fun = Findirect_function (object);
+  if (SUBRP (fun) && (EMACS_INT)XSUBR(fun)->src_file)
+    return build_string(XSUBR(fun)->src_file);
+  else
+    return Qnil;
+}
+
 DEFUN ("documentation", Fdocumentation, Sdocumentation, 1, 2, 0,
        doc: /* Return the documentation string of FUNCTION.
 Unless a non-nil second argument RAW is given, the
@@ -923,6 +949,8 @@
               doc: /* Name of file containing documentation strings of 
built-in symbols.  */);
   Vdoc_file_name = Qnil;
 
+  defsubr (&Ssource_line);
+  defsubr (&Ssource_file);
   defsubr (&Sdocumentation);
   defsubr (&Sdocumentation_property);
   defsubr (&Ssnarf_documentation);
Index: lisp/help-fns.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/help-fns.el,v
retrieving revision 1.30
diff -u -r1.30 help-fns.el
--- lisp/help-fns.el    12 Feb 2003 23:13:43 -0000      1.30
+++ lisp/help-fns.el    4 Apr 2003 07:52:52 -0000
@@ -225,7 +225,8 @@
                ((subrp def)
                 (if (eq 'unevalled (cdr (subr-arity def)))
                     (concat beg "special form")
-                  (concat beg "built-in function")))
+                  (concat beg "built-in function"))
+                (setq file-name (source-file function)))
                ((byte-code-function-p def)
                 (concat beg "compiled Lisp function"))
                ((symbolp def)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]