From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: ~`symbol-function' to get code as list even when byte-compiled? Date: Mon, 25 May 2015 19:37:47 +0200 Organization: Informatimago Message-ID: <87lhgc8sno.fsf@kuiper.lan.informatimago.com> References: <877frxid14.fsf@debian.uxu> <87siak1ssz.fsf@debian.uxu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1432575502 25795 80.91.229.3 (25 May 2015 17:38:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 25 May 2015 17:38:22 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon May 25 19:38:13 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YwwKK-0001mP-Qq for geh-help-gnu-emacs@m.gmane.org; Mon, 25 May 2015 19:38:12 +0200 Original-Received: from localhost ([::1]:44574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YwwKK-0005xJ-BB for geh-help-gnu-emacs@m.gmane.org; Mon, 25 May 2015 13:38:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41450) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YwwK9-0005x1-CN for help-gnu-emacs@gnu.org; Mon, 25 May 2015 13:38:02 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YwwK6-00011F-1q for help-gnu-emacs@gnu.org; Mon, 25 May 2015 13:38:01 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:43491) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YwwK5-00011A-QW for help-gnu-emacs@gnu.org; Mon, 25 May 2015 13:37:57 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1YwwK2-0001eu-4c for help-gnu-emacs@gnu.org; Mon, 25 May 2015 19:37:54 +0200 Original-Received: from amontsouris-654-1-18-241.w90-2.abo.wanadoo.fr ([90.2.153.241]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 25 May 2015 19:37:54 +0200 Original-Received: from pjb by amontsouris-654-1-18-241.w90-2.abo.wanadoo.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 25 May 2015 19:37:54 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 100 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: amontsouris-654-1-18-241.w90-2.abo.wanadoo.fr Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:N2Q4NDAzYTM5MDFlMDY2MWMyNzhhMzljMzZlYmNiNmZjNmJkZGJhNA== X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:104558 Archived-At: Emanuel Berg writes: > Barry Margolin writes: > >> You can probably prevent it from being compiled, >> maybe something like: >> >> (setf (symbol-function 'number-one-jump) '(lambda >> (&optional not-used) ...)) > > Yeah, but if I were to do special treatment, then > I might as well put > > (remove-hook 'w3m-display-hook 'number-one-jump) > > in "number-one-jump" and have it compiled like > all others! > > The reason for this idea, which I should have said in > the OP, is that I have many such jump functions, e.g.: > > (defun emacs-wiki-jump (&optional not-used) > (if (search-forward "EmacsWiki" (point-max) t) > (beginning-of-line) )) > > (defun urban-jump (&optional not-used) > (when (search-forward "Top Definition" (point-max) t) > (w3m-next-anchor) > (recenter-top-bottom 0) )) > > So instead of putting the corresponding remove-hook in > every one, this is what "enable-jump" does. Only it > doesn't work if the jump functions are compiled, which > didn't occurred to me when I got the idea and wrote > the code. > >> But can't you do something equivalent by using >> advice instead of self-modifying code? > > Possibly - how would that work? You could do something like this: (defun split-body (body) (loop with docstring = nil with declarations = '() for forms on body while (and forms (cond ((stringp (first forms)) (not docstring)) ((listp (first forms)) (member (first (first forms)) '(interactive declare))) (t nil))) do (if (stringp (first forms)) (setf docstring (first forms)) (push (first forms) declarations)) finally (return (list docstring (nreverse declarations) forms)))) (defmacro define-jump (name lamda-list &rest body) (destructuring-bind (docstring declarations body) (split-body body) `(progn (setf (get ',name 'jump-enabled) (list t nil)) (defun ,name ,lambda-list ,@(when docstring (list docstring)) ,@declarations (when (second (get ',name 'jump-enabled)) (remove-hook 'w3m-display-hook (quote ,name)) (setf (second (get ',name 'jump-enabled)) nil)) ,@body)))) (defun enable-jump (name) (unless (first (get name 'jump-enabled)) (error "%S is not a defined jump." name)) (setf (second (get name 'jump-enabled)) t) (add-hook 'w3m-display-hook name)) (define-jump number-one-jump (&optional not-used) ; Google, Youtube (when (re-search-forward "^ 1." (point-max) t) (recenter-top-bottom 0) (w3m-next-anchor))) (defun web-search () (interactive) (let ((search (get-search-string "Google"))) (unless (empty-string-p search) (w3m-new-tab (format "Google: %s" search)) (w3m-search w3m-search-default-engine search) )) (enable-jump 'number-one-jump)) -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk