From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: Why is defun not executed during load-file? Date: Sun, 30 May 2021 18:36:33 +0300 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2492"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0.7+183 (3d24855) (2021-05-28) Cc: help-gnu-emacs@gnu.org To: Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun May 30 17:38:07 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 1lnNVu-0000Qc-Gw for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 30 May 2021 17:38:06 +0200 Original-Received: from localhost ([::1]:49542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnNVt-0002lM-04 for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 30 May 2021 11:38:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42802) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnNVZ-0002lD-IK for help-gnu-emacs@gnu.org; Sun, 30 May 2021 11:37:45 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:40225) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnNVV-0007Sg-0R for help-gnu-emacs@gnu.org; Sun, 30 May 2021 11:37:45 -0400 Original-Received: from localhost ([::ffff:102.86.7.33]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 00000000000ADF01.0000000060B3B142.0000502D; Sun, 30 May 2021 08:37:37 -0700 Mail-Followup-To: Stefan Monnier , help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-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:130331 Archived-At: * Stefan Monnier via Users list for the GNU Emacs text editor [2021-05-30 16:32]: > Jean Louis [2021-05-30 12:02:25] wrote: > > I have this in the hyperscope.el and upon load-file the last function > > is not executed, it does not generate the functions. But if I evaluate > > it specifically, it generates functions. > > > > Is there any reason for that? > > > > (defun hyperscope-generate-the-add-function-by-hyperdocument-type (type-name id function-name) > > (eval `(defun ,(intern (symbol-name function-name)) () > > My crystal ball says it's punishment for using `eval` and recommends > using macro(s) instead. I wouldn't trust its judgment, but the > recommendation sounds useful anyway. > > BTW, `intern + symbol-name` ends up a no-op if `function-name` is > already an interned symbol. I just did not find a way to make it working. Now I have put more care and I got this to work: (defmacro hyperscope-generate-the-add-function-by-hyperdocument-type (type-name id function-name) (list 'defun function-name '() (format "Add new `%s' hyperdocument to Hyperscope." type-name) '(interactive) '(let* ((parent (hyperscope-select-set)) (prompt ,(format "New `%s' hyperdocument name: " type-name)) (name (read-from-minibuffer prompt))) (hlink-add-generic name "" ,id parent nil)))) (defun hyperscope-generate-add-functions-by-hyperdocument-types () (let ((types (hyperscope-hyperdocument-types))) (while types (let* ((type (pop types)) (id (nth 0 type)) (type (nth 1 type)) (type-name type) (type (downcase (string-replace " " "-" type))) (function-name (format "hyperscope-add-new-%s-hyperdocument" type))) (insert "\n" type-name " " id " " function-name) (hyperscope-generate-the-add-function-by-hyperdocument-type type-name id function-name))))) (hyperscope-generate-add-functions-by-hyperdocument-types) Now, this does not use `eval' and generates functions when I evaluate it. But again it will not generate functions when I load the file. Is that supposed to be so? This is smallest example: (defmacro my-generate-function (name) (list 'defun (intern name) '() "My function" '(interactive) '(message "hello"))) (my-generate-function "my-hello3") and that example works well, it does generate function `my-hello3' but my above doesn't. On the other hand I have observed if I do just one time: (fmakunbound 'hyperscope-add-new-markdown-hyperdocument) then this function will never be generated again in the same instance. I have to run another instance to be able to generate that function. Do you know why is that? -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns Sign an open letter in support of Richard M. Stallman https://stallmansupport.org/