From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: joaotavora@gmail.com (=?iso-8859-1?Q?Jo=E3o_T=E1vora?=) Newsgroups: gmane.emacs.devel Subject: Re: An easier way to edit variables Date: Wed, 14 Jan 2015 15:20:51 +0000 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1421248927 25807 80.91.229.3 (14 Jan 2015 15:22:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 14 Jan 2015 15:22:07 +0000 (UTC) Cc: emacs-devel@gnu.org To: Tom Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jan 14 16:22:02 2015 Return-path: Envelope-to: ged-emacs-devel@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 1YBPli-0008AH-2L for ged-emacs-devel@m.gmane.org; Wed, 14 Jan 2015 16:22:02 +0100 Original-Received: from localhost ([::1]:46763 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YBPlh-0005Za-Ia for ged-emacs-devel@m.gmane.org; Wed, 14 Jan 2015 10:22:01 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YBPl3-0004rS-4x for emacs-devel@gnu.org; Wed, 14 Jan 2015 10:21:25 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YBPkx-0006u3-E9 for emacs-devel@gnu.org; Wed, 14 Jan 2015 10:21:21 -0500 Original-Received: from mail-we0-x232.google.com ([2a00:1450:400c:c03::232]:39354) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YBPkx-0006tX-2r for emacs-devel@gnu.org; Wed, 14 Jan 2015 10:21:15 -0500 Original-Received: by mail-we0-f178.google.com with SMTP id p10so9361890wes.9 for ; Wed, 14 Jan 2015 07:21:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type:content-transfer-encoding; bh=1C4yvIE5pG7elH0yf+Ph/ZIuEfilgSV+QZoEw+QA6/0=; b=PM0BxOaRVvQaR0F/ENWT+RShIsIA/GqWSgnsipg4QmWmvna4YhiOg5lFygnZLJFXEm 7paGoGN14dGYAJ5Q4n9P4vHhKSNKeXoA63C6980cstEv930AINhttpQf6D+sfula4Eqo yQX+OTYEJwXo0nAuoHOaW1zjtsiABF+JNAVv3563vhNBya/uaNddmRSimPlimYtaKjpM 0AfVW1D4hbv9imAwSlPY5njOsVdORs3EgZq+bE6ps5CAnOTiOIVhe9SsnS6tf9p8/Og3 eRpnBc7qdegokweCeQeIbJ/rpfSr7HpjSK7vesDm63AgkcuK61Ix8jac6v5d2pOG6etL 4HrA== X-Received: by 10.180.24.138 with SMTP id u10mr9459830wif.80.1421248873917; Wed, 14 Jan 2015 07:21:13 -0800 (PST) Original-Received: from GONDOMAR.yourcompany.com (mail3.siscog.pt. [195.23.29.18]) by mx.google.com with ESMTPSA id fx6sm30475766wjc.39.2015.01.14.07.21.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Jan 2015 07:21:12 -0800 (PST) In-Reply-To: (Tom's message of "Tue, 13 Jan 2015 22:11:40 +0000 (UTC)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (windows-nt) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c03::232 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:181253 Archived-At: Tom writes: > Tom gmail.com> writes: >>=20 >> I think it was pressing e for edit in the Help buffer, then >> the buffer is narrowed to the variable value only (which can be a=20 >> complex list or anything) which you can modify in place and >> then press C-c C-c to apply it to the variable and exit >> edit mode. >>=20 > > BTW, I should add that when I wrote "easier" in the subject I=20 > meant easier for Lisp hackers who change Lisp variables on > a daily basis. > > That's why a quick edit feature in the Help buffer is useful, because > you already see the value there, so if it's complex list > (e.g. a font lock setting or anything) then you don't have to > copy it etc, if you just want to change one thing in it, > you just press e, you get the lisp value, you edit it, > press C-c C-c and it is applied instantly. I still find this idea very good. Some time ago, I presented a quick hack for this in https://lists.gnu.org/archive/html/emacs-devel/2014-01/msg01053.html You made some comments, but the discussion died or something. Here's a not-so-quick hack that addresses those concerns. It emulates widgets in the *Help* buffer and you edit the variable's value in place. Should support buffer-local vars but I didn't test much. Also no "eval" is used, the form is just read back much like it was printed. It's still a bit broken in, bringing the field to 0-length breaks it. Should use an overlay. And maybe use "proper" widgets? Probably broken in more ways I didn't see. Still, can anyone test it and give me some feedback? The diff is against emacs-24.4 sorry, I'm on windows and no git clone.=20 Jo=E3o *** z:/Vendor/emacs-w64-24.4/share/emacs/24.4/lisp/help-fns.el.gz --- z:/Vendor/emacs-24.4/share/emacs/24.4/lisp/help-fns.el *************** *** 610,615 **** --- 610,686 ---- version package)))))) output)) =20=20 + (defun help--editable-find-near-point (&optional pos) + (let* ((pos (or pos (point))) + (field-pos + (if (eq 'help--editable-field (car (field-at-pos pos))) + pos + (let ((p (point-min))) + (while (and (setq p (next-single-property-change p 'field)) + (not (eq 'help--editable-field (car (field-at-p= os p)))))) + p)))) + (or field-pos + (error "No editable field found")))) +=20 + (defun help-edit-editable-field (field-pos) + (interactive (list (help--editable-find-near-point))) + (read-only-mode -1) + (let ((start (field-beginning field-pos)) + (end (field-end field-pos))) + (add-text-properties + (point-min) start + '(rear-nonsticky (read-only) read-only t)) + (put-text-property end (point-max) 'read-only t) + (add-text-properties + start end + `(local-map ,help--editing-field-keymap + face widget-field + font-lock-face 'widget-field + front-sticky (face font-lock-face field local-map))))) +=20 + (defun help-commit-editable-field (field-pos) + (interactive (list (help--editable-find-near-point))) + (let* ((field (field-at-pos field-pos)) + (string (field-string-no-properties field-pos)) + (read (car (read-from-string string))) + (variable (cdr (assoc 'variable (cdr field)))) + (locus (cdr (assoc 'locus (cdr field))))) + (cond ((bufferp locus) + (with-current-buffer locus + (set (make-local-variable variable) read))) + (t + (set-default variable read))) + (help-quit-editable-field field-pos))) +=20 + (defun help-quit-editable-field (_field-pose) + (interactive (help--editable-field-interactive)) + ;; TODO: a better implementation might be to restore the text + ;; properties and the text according to the + ;; `original-representation' prop. But this is safer for now. + (revert-buffer nil t)) +=20 + (defvar help--editable-field-keymap + (let ((map (make-sparse-keymap))) + (define-key map (kbd "v") 'help-edit-editable-field) + map)) +=20 + (defvar help--editing-field-keymap + (let ((map (make-sparse-keymap))) + (define-key map (kbd "C-c C-c") 'help-commit-editable-field) + (define-key map (kbd "C-c C-q") 'help-quit-editable-field) + map)) +=20 + (defun help--insert-editable-field (variable + representation + &optional locus) + (insert (propertize + representation + 'field `(help--editable-field + . ((original-representation . ,representation) + (variable . ,variable) + (locus . ,locus))) + 'keymap help--editable-field-keymap))) +=20 ;;;###autoload (defun describe-variable (variable &optional buffer frame) "Display the full documentation of VARIABLE (a symbol). *************** *** 684,692 **** (let ((print-quoted t)) (prin1-to-string val)))) (if (< (+ (length print-rep) (point) (- line-beg)) 68) ! (insert print-rep) (terpri) ! (pp val) (if (< (point) (+ 68 (line-beginning-position 0))) (delete-region from (1+ from)) (delete-region (1- from) from))) --- 755,765 ---- (let ((print-quoted t)) (prin1-to-string val)))) (if (< (+ (length print-rep) (point) (- line-beg)) 68) ! (help--insert-editable-field variable ! print-rep ! locus) (terpri) ! (help--insert-editable-field variable (pp-to-string val) locus) (if (< (point) (+ 68 (line-beginning-position 0))) (delete-region from (1+ from)) (delete-region (1- from) from))) *************** *** 728,734 **** ;; probably print it raw once and check it's a ;; sensible size before prettyprinting. -- fx (let ((from (point))) ! (pp global-val) ;; See previous comment for this function. ;; (help-xref-on-pp from (point)) (if (< (point) (+ from 20)) --- 801,807 ---- ;; probably print it raw once and check it's a ;; sensible size before prettyprinting. -- fx (let ((from (point))) ! (help--insert-editable-field variable (pp-to-stri= ng global-val)) ;; See previous comment for this function. ;; (help-xref-on-pp from (point)) (if (< (point) (+ from 20))