From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Dalton Newsgroups: gmane.emacs.help Subject: Re: A couple of emacs lisp questions Date: Thu, 23 Dec 2010 12:08:59 +1100 Message-ID: <20101223010859.GA9006@gwsc.vic.edu.au> References: <20101221131820.GA24113@gwsc.vic.edu.au> <95C1839A334140008F8D40431F62E23B@us.oracle.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1293066611 7912 80.91.229.12 (23 Dec 2010 01:10:11 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 23 Dec 2010 01:10:11 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Drew Adams Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 23 02:10:07 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PVZh0-00082U-LX for geh-help-gnu-emacs@m.gmane.org; Thu, 23 Dec 2010 02:10:06 +0100 Original-Received: from localhost ([127.0.0.1]:51512 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PVZgz-0006m7-S4 for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Dec 2010 20:10:05 -0500 Original-Received: from [140.186.70.92] (port=58683 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PVZgC-0006kn-9J for help-gnu-emacs@gnu.org; Wed, 22 Dec 2010 20:09:18 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PVZg7-0001Li-Uc for help-gnu-emacs@gnu.org; Wed, 22 Dec 2010 20:09:16 -0500 Original-Received: from outbound.icp-qv1-irony-out6.iinet.net.au ([203.59.1.109]:38585) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PVZg7-0001Kq-If for help-gnu-emacs@gnu.org; Wed, 22 Dec 2010 20:09:11 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApYIAMQvEk18qHQm/2dsb2JhbACkJnNKwnqFSQSLA4M3 X-IronPort-AV: E=Sophos;i="4.60,216,1291564800"; d="scan'208";a="184929723" Original-Received: from unknown (HELO localhost) ([124.168.116.38]) by outbound.icp-qv1-irony-out6.iinet.net.au with ESMTP; 23 Dec 2010 09:09:00 +0800 Content-Disposition: inline In-Reply-To: <95C1839A334140008F8D40431F62E23B@us.oracle.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:77802 Archived-At: Hi Drew, Thanks so much for the detailed response. Please see my comments below. On Tue, Dec 21, 2010 at 10:12:03AM -0800, Drew Adams wrote: > > 1. I need to make 5 or 6 key bindings. I presume the way to do this is > > to create a prefix and then put my bindings under this. So perhaps the > > prefix could be c-c c-l and then I can create key bindings to trigger > > certain functions i.e.e c-c c-l t toggles the functionality on/off. > > How would I implement something like this? > > C-h r i prefix key RET takes you to the Emacs manual node `Prefix Keys', which > provides some help. > I shall take a look. > ;; Define a keymap variable for your prefix-key commands: > (defvar my-map () "My prefix key.") > > ;; Define the keymap as a prefix-key command: > (define-prefix-command 'my-map) > > That defines `my-map' as a command whose function definition and whose value are > the same, new (empty) keymap. More info: > > C-h f define-prefix-command > C-h v my-map > C-h f my-map > > ;; Bind command `my-map' to a key - the prefix key: > (global-set-key "\C-c\C-l" 'my-map) > > ;; Bind cmds `foo' & `bar' to `a' & `b' following the prefix key: > (define-key my-map "a" 'foo) > (define-key my-map "b" 'bar) Oh, that all seems to be fairly logical and make sense. > > How could I record the current key bindings which use c-c c-l as a > > prefix, and then restore them upon exit of the latex-access > > stuff. I.e. when it is disabled. > > Note, that I haven't created a minor or major mode, I'm just > > using hooks > > and advice as well as interactive functions to make my work available > > under emacs. > > OK, let's start over from a clean slate (new Emacs session, to get rid of > bindings etc. we created). > > You don't want the prefix key defined globally, but just in your (minor) mode. Are you suggesting I should make my code into a minor mode? What work is involved to do this? Perhaps I should look at the docs. Currently I just have about a dozen different functions, most interactive which are called when necessary. I use hooks and advice to make my code execute... How different would my implementation have to be if I built a minor mode? Would I have to change much? And what benefits would there be in doing this? > ;; Create a keymap for your minor mode, and define the mode. > (defvar latax-mode-map (make-sparse-keymap) > "LaTeX access minor mode keymap.") > > (define-minor-mode latax-mode "LaTeX access mode." > nil " LaTax" latax-mode-map) > What is the Latax-mode stuff for? I thought we are creating a minor mode for latex-access? > ;; Create the prefix-key keymap. > (defvar latax-prefix-map nil > "LaTeX access mode prefix keymap.") > > ;; Bind command `latax-prefix-map' to `C-c C-l' in `latex-mode-map': > (define-key latax-mode-map "\C-c\C-l" 'latax-prefix-map) > > ;; Bind other commands in the prefix map: > (define-key latax-prefix-map "a" 'forward-char) > (define-key latax-prefix-map "b" 'emacs-version) > > Turn on/off the minor mode: `M-x latax-mode'. Oh I think I understand now. So where should this code go? In a particular function definition? Or just straight in the .el file. Currently I have 3 or 4 toggling functions, to change different behaviour of the mode, could I still use these? When the mode is disabled, I suppose all my interactive latex-access functions would still be available though through m-x? > Dunno. Sounds like you should just display another buffer (always), and send the > output you want there. See `with-current-buffer' and the like. I think that sounds like a good idea. > > For fitting the window to the buffer, see `resize-temp-buffer-window' and > `fit-window-to-buffer'. > > You can also use a separate frame for the buffer - see `special-display-regexps' I had a play, only thing that was a bit annoying, which I wouldn't mind removing is the header and mode lines from the output buffer... I was just using a standard buffer, is this different for temp buffer? If I use a temp buffer, won't it get destroyed or have I misunderstood the temp buffer setup? > and `special-display-buffer-names'. If you do that, you can use `fit-frame' in > library `fit-frame.el' to fit the frame to the buffer. > http://www.emacswiki.org/emacs/FrameModes#ShrinkWrappedFrames That's something else I will checkout for sure. I'm probably going to have a go at implementing this in the next week or so (after Christmas), may I contact you directly if I run into problems? Once again thanks very much for your comprehensive response! Kind regards, Daniel Dalton