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: don't understand setq-default Date: Sun, 18 Apr 2021 16:59:38 +0200 Message-ID: <87blaby6xx.fsf@omarpolo.com> References: <87mttvx1lo.fsf@zoho.eu> <87eef7ycd9.fsf@omarpolo.com> <87blabww2u.fsf@zoho.eu> <877dkzww0r.fsf@zoho.eu> <8735vnwu8z.fsf@zoho.eu> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35261"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.15; emacs 28.0.50 Cc: help-gnu-emacs@gnu.org To: Emanuel Berg Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Apr 18 17:00:18 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 1lY8uI-00095a-51 for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 18 Apr 2021 17:00:18 +0200 Original-Received: from localhost ([::1]:33552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lY8uH-0000hY-60 for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 18 Apr 2021 11:00:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lY8to-0000hR-0L for help-gnu-emacs@gnu.org; Sun, 18 Apr 2021 10:59:48 -0400 Original-Received: from mail.omarpolo.com ([144.91.116.244]:62309) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lY8ti-00021c-AF for help-gnu-emacs@gnu.org; Sun, 18 Apr 2021 10:59:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=omarpolo.com; s=20200327; t=1618757979; 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: in-reply-to:in-reply-to:references:references; bh=b0RGX8wulN2bmbO0uWd/sBd8QYcz28YAhKhi90zkYD8=; b=RE9Eg0LORfX+rnzM+FoK4aKROmtR3G/C0JdBfvMq0LFwFGl/GiayzGf9+TwvaVxcUSfwCH oGMMh3m7A3zKSSFkbXY/FFeYfsLStwjlPuOOmKCRySqsdQUQF704+Jmn0+j6eH9EdnOLO9 gw7Tl+/Qji3kBxik1pfHxf+/xliqduU= Original-Received: from localhost (host-87-2-232-216.retail.telecomitalia.it [87.2.232.216]) by mail.omarpolo.com (OpenSMTPD) with ESMTPSA id c16396c9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sun, 18 Apr 2021 16:59:39 +0200 (CEST) Original-Received: from venera (localhost [127.0.0.1]) by localhost (OpenSMTPD) with ESMTP id e4cb703d; Sun, 18 Apr 2021 16:59:38 +0200 (CEST) In-reply-to: <8735vnwu8z.fsf@zoho.eu> 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:129035 Archived-At: Emanuel Berg via Users list for the GNU Emacs text editor writes: >>> OK, that explains it, buffer local values, I can't even >>> keep track of the buffers... >> >> I have used it 8 times, maybe change to setq to force >> everywhere... > > Worst thing that can happen, it will show, where I need even > more force... > > Wait, I sense there is something wrong with this thinking... > > with setq, global var > > with setq-default default val for var if not buffer-local > > how do you look for the buffer-local var? > > I take it that takes precedence? > > yeah, it is the compass needle all over that acts on the > GLOBAL Earth's magnet, only put the local magnet next to > the compass, proximity overrules size > > you set the buffer-locals or they set themselves thru hooks > or implications from setq "automatically when set" > > how do I know my globals - me thinking them are - aren't > actually as they gets trapped in some Elisp file where > I eval'd them which has nothing to do with it, even? > Eval a config file for ERC, all that goes into the Elisp > file LOL. > > How do you tell a var should be buffer-local when set? Nah, > I don't want to know. They are not part of my strategy. > But please tell my all buzzwords so I can go on pruning > my Elisp, always a good feeling :) [ keep in mind that I'm not really an expert elisp hacker ] Try to keep it simple. buffer-local variables sometimes are useful. Let's take the indent-tabs-mode variable for instance: you set it to t to enable hard tabs, or nil if you don't. For some modes you may want to use tabs (e.g. C, or Go), while for others spaces (may) be mandatory (i.e. python), so a global variable won't do it (you won't be able to switch between C and python files without messing up the indentation :P) Another example: I'm writing a chat application in elisp. I have a, say, toxe-friend-name that holds the name of the chat you've opened. It's useful to keep this a buffer-local, so it gets a different value per chat-buffer, and the elisp code is simple. Sometimes this don't make sense: emacs-version probably doesn't need to be buffer local, so judgement is needed. C-h v tells you when a variable becomes buffer-local when set, or if it's local to the current buffer, so you may want to check that. It even tells you its "default" and "local" value, which can get useful. You get the buffer-local value when you're running a bit of elisp inside that buffer. (I don't know how to retrieve the global value, but a short trip to the manual should tell me that) So, for example: (defvar my-var 5) my-var ;; => 5 (with-current-buffer (get-buffer-create "test") (message "my-var is %d" my-var) (make-local-variable 'my-var) (setq my-var 7) (message "my-var is %d" my-var) (setq-default my-var 'foo) (message "my-var is %d" my-var)) ;; my-var is 5 ;; my-var is 7 ;; my-var is 7 my-var ;; => foo HTH