From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: avoiding global variables (was: Re: if and only if an Error message) Date: Mon, 21 Jul 2014 00:48:17 +0200 Organization: Aioe.org NNTP Server Message-ID: <87tx6br6j2.fsf_-_@debian.uxu> References: <87tx6e2tr1.fsf@gmail.com> <87vbqu1721.fsf@debian.uxu> <871ttijfiy.fsf@web.de> <87k37a1569.fsf@debian.uxu> <87vbqu9fpd.fsf_-_@debian.uxu> <8761iu6l9u.fsf@debian.uxu> <87iomu54xq.fsf@debian.uxu> <87d2d253u1.fsf@debian.uxu> <87lhrpd0wq.fsf@debian.uxu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1405896640 10972 80.91.229.3 (20 Jul 2014 22:50:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 20 Jul 2014 22:50:40 +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 Jul 21 00:50:34 2014 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 1X8zwA-0006nU-4f for geh-help-gnu-emacs@m.gmane.org; Mon, 21 Jul 2014 00:50:34 +0200 Original-Received: from localhost ([::1]:59440 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X8zw9-0003EL-Ne for geh-help-gnu-emacs@m.gmane.org; Sun, 20 Jul 2014 18:50:33 -0400 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!news.stack.nl!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 65 Original-NNTP-Posting-Host: SIvZRMPqRkkTHAHL6NkRuw.user.speranza.aioe.org Original-X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:lvmCJq+3oqOwJUupQsazm34j1Mg= Mail-Copies-To: never Original-Xref: usenet.stanford.edu gnu.emacs.help:206571 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:98842 Archived-At: I thought perhaps the new insights on dynamic and lexical scope could help me with a problem I've had a couple of times. I think the reason I never had any problems with dynamic vs. lexical is the way I almost exclusively used identifiers that were either of `let's or function parameters. But I came to think of one case that wasn't so, and an example of that I posted in the thread on the debugger (code last). Here, is there any way to not make `error-buffer-name' global but to associate it exclusively with the two defuns that use it? If it were part of an interface for other Elisp to perhaps use, a global variable is one way of doing that, but when I wrote it, I have to admit I only made it global so that both defuns could get access to it. The only way I can think of not having it that way is to merge the two defuns, then have them separated internally with `labels' (`cl-labels'), and used the one or the other a function of an argument - and that would be... bulky. If it is OK to use global like this, should you rely on long and original prefixes to avoid collisions? Or should you just code whatever you like and solve collisions if/when they appear? It is not like this is a Mars expedition or something. Still... it is the attitude. It doesn't matter if you recycle cans or do stock exchange, you want to be all slick just the same. (setq error-buffer-name "*Errors*") ;; inhibit the debugger - ;; try this if nothing else: a wonderful thing to not ;; have it hop out over half the screen for something ;; that can be communicated in a few words (setq debug-on-error nil) (setq eval-expression-debug-on-error nil) (defun say-and-log-error (data _ fun) (let*((error-str (format "%S in %S" data fun)) (error-buffer (get-buffer-create error-buffer-name)) (error-win (get-buffer-window error-buffer)) ) (message error-str) ; echo the error message (with-current-buffer error-buffer (goto-char (point-max)) (insert error-str "\n") ) ; log it (if error-win (with-selected-window error-win ; move focus of error window (goto-char (point-max)) ; if visible (recenter -1)) ))) ; (is there a better way?) (setq command-error-function (lambda (&rest args) (apply #'say-and-log-error args)) ) (defun show-errors () (interactive) (switch-to-buffer (get-buffer-create error-buffer-name)) (goto-char (point-max)) ; the same situation: the last line of data (recenter -1) ) ; should be on the last window line ; whenever possible ; test here: ; (message 'error-as-not-string) -- underground experts united