From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Omar Polo Newsgroups: gmane.emacs.help Subject: Re: The convenient method to check/inspect/retrieve the definition/usage of any commands/symbols/operators used in elisp code. Date: Wed, 23 Jun 2021 09:48:56 +0200 Message-ID: <8735t96mxj.fsf@omarpolo.com> References: <87sg1dgbbk.fsf@omarpolo.com> <87pmwhg843.fsf@omarpolo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9391"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.15; emacs 28.0.50 Cc: help-gnu-emacs@gnu.org To: Hongyi Zhao Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 23 09:49:55 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lvxdy-0002Ee-JB for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 23 Jun 2021 09:49:54 +0200 Original-Received: from localhost ([::1]:51920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lvxdw-0001IV-RI for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 23 Jun 2021 03:49:52 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54802) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lvxdO-0001I5-Lw for help-gnu-emacs@gnu.org; Wed, 23 Jun 2021 03:49:18 -0400 Original-Received: from mail.omarpolo.com ([144.91.116.244]:53046) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lvxdI-0005fr-OL for help-gnu-emacs@gnu.org; Wed, 23 Jun 2021 03:49:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=omarpolo.com; s=20200327; t=1624434542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+cIWejcy3TaAQHnpL0QNUIc7/RJ/w+9mG0UD0Q++8kA=; b=aJlI+RilZQiLHzsiZgF725CYqLfROdm5iJ1nRfbfT8zEhSsEeKBTH+EgLT83MJCPlZ1vR8 /HqeObl1YI5F5ujCHyit92aZYrukEk42Yqty7vI8YvECb1gYgggdboFKO5pXvksiAzUb7V /ifV0JH2uNQtn3RK/++mpNmM7iJB6+w= Original-Received: from localhost (host-79-16-11-173.retail.telecomitalia.it [79.16.11.173]) by mail.omarpolo.com (OpenSMTPD) with ESMTPSA id 534e2eb3 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 23 Jun 2021 09:49:01 +0200 (CEST) Original-Received: from venera (localhost [127.0.0.1]) by localhost (OpenSMTPD) with ESMTP id 6727dc8b; Wed, 23 Jun 2021 09:48:56 +0200 (CEST) In-reply-to: Received-SPF: pass client-ip=144.91.116.244; envelope-from=op@omarpolo.com; helo=mail.omarpolo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:131208 Archived-At: (sorry for the delay) Hongyi Zhao writes: > On Sat, Jun 19, 2021 at 11:57 PM Omar Polo wrote: >> >> >> Hongyi Zhao writes: >> >> > On Sat, Jun 19, 2021 at 10:48 PM Omar Polo wrote: >> >> >> >> >> >> Hongyi Zhao writes: >> >> >> >> > Dear all, >> >> > >> >> > Are there any built-in method of Emacs which can let me conveniently >> >> > check/inspect/retrieve the definition/usage of any >> >> > commands/symbols/operators used in elisp code at-the-point/in-situ? >> >> > Say, for the following code snippets: >> >> > >> >> > ;;; >> >> > (defun fk/company-wordfreq-toggle-language (&optional language) >> >> > (interactive) >> >> > (setq ispell-local-dictionary (or language >> >> > (if (string=3D >> >> > ispell-local-dictionary "english") >> >> > "turkish" >> >> > "english"))) >> >> > [...] >> >> > `(progn >> >> > ,@(mapcar (lambda (p) `(use-package ,p)) >> >> > packages))) >> >> > >> >> > (use-multiple-packages flycheck >> >> > dash >> >> > ) >> >> > >> >> > [...] >> >> > (mapcar #'straight-use-package '(flycheck lsp-mode dash ...)) >> >> > >> >> > ;or equivalently >> >> > >> >> > (defvar my-package-list '(flycheck lsp-mode dash ...)) >> >> > (mapcar #'straight-use-package my-package-list) >> >> > ;;; >> >> > >> >> > I want to find some convenient methods built in Emacs itself with an >> >> > in-situ manner - by moving the point to the interest position - to >> >> > check any commands/symbols/operators used in them. >> >> > >> >> > Regards >> >> >> >> there is M-. (xref-find-definitions) that will jump to the definition= of >> >> the symbol at point (at least in emacs lisp buffers), >> > >> > Thank you very much. But still there are some symbols can't find with >> > this method, say, #' ,@ ' and so on. >> >> #' ' ` , and ,@ aren't symbols, they are reader macros, i.e. special >> character sequences that the lisp reader expands into some special >> constructs. For instance, #'foo is the same as (function 'foo) and 'foo >> the same as (quote foo). >> >> If you M-. with the point over quote (in an elisp buffer) it should jump >> to eval.c (assuming you have the C source files available). >> >> >> and M-, (xref-pop-marker-stack) to jump back. >> > >> > I use scratch buffer to test, and it can't jump back there. >> >> M-, is meant to be used after one or more M-. >> >> For instance: >> >> 1. in *scratch* type describe-function >> 2. press M-. -- it'll jump to help-fns.el.gz >> 3. move the point over with-help-window (something like ~10 lines below) >> 4. M-. again -- it'll jump to a different place in the same file >> 5. go back with M-, -- now you're back in the definition of >> describe-function >> 6. M-, again -- now you're back in the *scratch* buffer > > Wonderful explanations. But I still failed to reproduce the M-, , as > for the other steps you told above except the last two, I can > reproduce them exactly the same as you described. > > See the attachment for the info I saw on the bottom mini-buffer when > hitting M-, (M- comma). don't want to sound rude, but could you please refrain from attaching a whole screenshot just for an error message? Copying the error, like: "it says that: buffer is read-only" it's enough IMHO. (you'll find a copy of the error message in the *Messages* buffer if you don't want to type it by hand.) Now, usually that error is signaled when you try to insert something into a buffer that read-only. There can be multiple reasons for that, but unfortunately I thinks it's something on your end, since I cannot reproduce with `emacs -Q'. Make sure that you are hitting M-, and not the comma alone, or ensure that M-, is bound to xref-pop-marker-stack and not to something else (C-h k M-,) As en extreme solution, try to enable the debug-on-error (M-x toggle-debug-on-error RET) and look at the stacktrace when that error happens. (You can use toggle-debug-on-error again to disable it later) >> >> >> >> >> Or you can C-h f or C-h v (describe-function/variable) and then M-n >> >> (next-history-element) to bring in the symbol at point. >> > >> > I meet the following message: M-n is undefined, as shown in the >> > attached screenshot file. >> >> M-n should be defined in some minibuffer maps; with `emacs -Q' I can >> >> C-h v C-h k M-n >> >> and it tells me that. > > I got the following with your above command sequence: > > M-n runs the command next-history-element (found in > minibuffer-local-must-match-map), which is an interactive compiled > Lisp function in =E2=80=98simple.el=E2=80=99. > > It is bound to , , M-n, > . > > (next-history-element N) > > Puts next element of the minibuffer history in the minibuffer. > With argument N, it uses the Nth following element. The position > in the history can go beyond the current position and invoke "future > history." Yep. Sorry for giving a long command sequence without any explanation. `C-h v' is describe-variable, it should enter the minibuffer asking for a variable to be described. Then `C-h k' is describe-key, that works in the minibuffer too. M-n is bound to next-history-element there too, so it should work. When you are over (or at the beginning) of a symbol, M-n should pull that symbol into the minibuffer. So with the cursor over toggle-debug-on-error if I type `C-h f' (describe-function) and then M-n, Emacs automatically inserts "toggle-debug-on-error" as input in the minibuffer. Then I can simply RET to read the documentation of the function :) > HY > >> >> > M-n runs the command next-history-element (found in >> > minibuffer-local-must-match-map), which is an interactive compiled >> > Lisp function in =E2=80=98simple.el=E2=80=99. >> >> Cheers, >> >> > HY >>