all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* special-mode buffer changes to fundamental when modified
@ 2016-10-20  2:25 Stefan Huchler
  2016-10-20 15:33 ` Michael Heerdegen
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Huchler @ 2016-10-20  2:25 UTC (permalink / raw)
  To: help-gnu-emacs

I try something like that:


(define-derived-mode foo-mode special-mode "foo"
  
  (with-current-buffer-window "*foo*" nil nil
   (print (concat "...:\n"
   		  (substitute-command-keys
   		   "\\{foo-mode-map}") ))
   ) 
  )

but then its no special mode buffer anymore, and it
overwrites my keymaps. Without the with-current-buffer-window macro it
works it supposed to be but the buffer is empty.

I tried I think most with- macros and nothing worked, not very obvious
for me how to write stuff in a special buffer.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: special-mode buffer changes to fundamental when modified
  2016-10-20  2:25 special-mode buffer changes to fundamental when modified Stefan Huchler
@ 2016-10-20 15:33 ` Michael Heerdegen
  2016-10-20 16:34   ` Stefan Huchler
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Heerdegen @ 2016-10-20 15:33 UTC (permalink / raw)
  To: Stefan Huchler; +Cc: help-gnu-emacs

Stefan Huchler <stefan.huchler@mail.de> writes:

> I try something like that:
>
>
> (define-derived-mode foo-mode special-mode "foo"
>   
>   (with-current-buffer-window "*foo*" nil nil
>    (print (concat "...:\n"
>    		  (substitute-command-keys
>    		   "\\{foo-mode-map}") ))
>    ) 
>   )

That looks very strange.  A mode definition should not make a particular
buffer current.  It should work in any (current) buffer where the mode
is enabled.

> but then its no special mode buffer anymore, and it overwrites my
> keymaps. Without the with-current-buffer-window macro it works it
> supposed to be but the buffer is empty.

Hard to guess what you want to do.  Maybe you confuse `print' with
`insert' or something else?

> I tried I think most with- macros and nothing worked, not very obvious
> for me how to write stuff in a special buffer.

In Emacs, trial and error doesn't work most of the time, you'll get
always "error" ;-)


Michael.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: special-mode buffer changes to fundamental when modified
  2016-10-20 15:33 ` Michael Heerdegen
@ 2016-10-20 16:34   ` Stefan Huchler
  2016-10-21 10:58     ` Michael Heerdegen
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Huchler @ 2016-10-20 16:34 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:


> That looks very strange.  A mode definition should not make a particular
> buffer current.  It should work in any (current) buffer where the mode
> is enabled.

Again I used first other methods like with-temp-buffer and stuff like
that, but it always either dont insert the stuff I want, or it changes
the mode of the buffer to fundamental mode.

>> but then its no special mode buffer anymore, and it overwrites my
>> keymaps. Without the with-current-buffer-window macro it works it
>> supposed to be but the buffer is empty.
>
> Hard to guess what you want to do.  Maybe you confuse `print' with
> `insert' or something else?

I used first princ or prin1 doesnt fix it. If I try insert, it tells me
that its read only.

I dont confuse it, just in the source of other mode, people often if not
always use something like with-temp-buffer to insert content there.

I want to have some text in the new buffer, thats what I want to do.

>
> In Emacs, trial and error doesn't work most of the time, you'll get
> always "error" ;-)

Yes because of that, I wrote this question, else I would gone more try &
error.

The try and error were some sort of last resort, cause the api
documentation is pretty bad on this aspect.

Also there are no simple examples out there too, the real
"documentation" you get to develop such modes is looking the source of
other modes.

And they are often very complex, I dont know every of the 5000 elisp
functions so its hard to read that often very complex code, when I only
want to make pretty simple stuff.

So insert does not work, too, including toggle-read-only before that
(nor is it meant to be used in source). its not that I gone for strange
with-*-buffer functions because it was the obvious way to do so, its
because insert does not work for read-only-buffers and people use this
with-* constructs in similar buffers/modes apperently for that purpose.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: special-mode buffer changes to fundamental when modified
  2016-10-20 16:34   ` Stefan Huchler
@ 2016-10-21 10:58     ` Michael Heerdegen
  2016-10-22  0:15       ` Stefan Huchler
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Heerdegen @ 2016-10-21 10:58 UTC (permalink / raw)
  To: Stefan Huchler; +Cc: help-gnu-emacs

Stefan Huchler <stefan.huchler@mail.de> writes:

> > That looks very strange.  A mode definition should not make a
> > particular buffer current.  It should work in any (current) buffer
> > where the mode is enabled.
>
> Again I used first other methods like with-temp-buffer and stuff like
> that, but it always either dont insert the stuff I want, or it changes
> the mode of the buffer to fundamental mode.

Ok, then please tell us a bit more about what you want to achieve, and
what the mode you want to define is supposed to do.


Michael.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: special-mode buffer changes to fundamental when modified
  2016-10-21 10:58     ` Michael Heerdegen
@ 2016-10-22  0:15       ` Stefan Huchler
  2016-10-23 11:41         ` Michael Heerdegen
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Huchler @ 2016-10-22  0:15 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Ok, then please tell us a bit more about what you want to achieve, and
> what the mode you want to define is supposed to do.

Well, I am the author of kodi-remote.el it startet as some functions to
send a video/youtube url to kodi and start music party-mode. But
recently I startet to implement a whole remote for emacs.

Basicly the idea is to have keyboard mode so you can control a kodi
instance like you would have connected the keyboard direct on the
machine that runs kodi.

On top of that I have a kodi series mode that shows me at the moment the
unseen stuff and lets me start a video.

There I have other problems like getting the refresh functionality to
work at the moment it only kind of refreshes if I restart the mode, and
even that not really consistent.

But that is another problem, but a similar one, cause its also about
such special mode buffers (there I use tabulated mode).

In the end I would want, if that makes sense have one major
kodi-remote-buffer as start-point, and the other modes as sub-buffers.

For this thread I was targeting the keyboard mode, functional wise it
does what it should do, it sends kodi commands according to the keys you
press.

But I cant make this a empty special buffer, then most people would have
no idea what to do if they start this mode/function. So I thought lets
display the keybbindings for now.

In the end maybe I dont know what would be best, a mouse interface, I
dont know. But to get some sort of version out there I thought
displaying the keybindings and a header line would be ok.

Its just a bit much, trying to gasp emacs internals, elisp, the json-api
from kodi and designing a good interface so I have to have milestones between
that. Also the current patch will be huge anyway, so I am not trying to
get all right, but have something a user can get around if he is a bit
interested in such software.

In the end there could be some minor modes, there could be youtube-eww
integration etc, (I use it to send youtube-urls from other browsers like
conkeror and qutebrowser with something like that:

 var cmd = '/usr/bin/emacsclient -e "(kodi-remote-play-video-url
 \\"{}\\")"'

and

hint links spawn emacsclient -e "(kodi-remote-play-video-url \"{hint-url}\")"
    y

because I am to lazy to write for each browser a own youtube-plugin, but
thats maybe to much detail now.

So did you understand what I wanna do? I can give you the real source
code not the abstracted here:


(defvar kodi-remote-keyboard-mode-map
  (let ((map (make-sparse-keymap))
	(menu-map (make-sparse-keymap)))
....
    (define-key map (kbd "-") 'kodi-remote-volume-decrease)
    (define-key map (kbd "<tab>") 'kodi-remote-toggle-fullscreen)
    map)
  "Keymap for kodi-remote-keyboard-mode.")

(define-derived-mode kodi-remote-keyboard-mode special-mode "kodi-remote-keyboard"
  "Major mode for remote controlling kodi instance with keyboard commands 
Key bindings:
\\{kodi-remote-keyboard-mode-map}"
  (toggle-read-only)
  (insert (concat "Kodi Remote:\n"
		  (substitute-command-keys
		   "\\{kodi-remote-keyboard-mode-map}") ))
  )

(defun kodi-remote-keyboard ()
  "Open a `kodi-remote-keyboard-mode' buffer."
  (interactive)
  (let* ((name "*kodi-remote-keyboard*")
         (buffer (or (get-buffer name)
                     (generate-new-buffer name))))
    (unless (eq buffer (current-buffer))
      (with-current-buffer buffer
        (unless (eq major-mode 'kodi-remote-keyboard-mode)
          (condition-case e
              (progn
                (kodi-remote-keyboard-mode)
		)
            (error
             (kill-buffer buffer)
             (signal (car e) (cdr e))))))
      (switch-to-buffer-other-window buffer))))


That should be the relevant part.

greetings

Stefan




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: special-mode buffer changes to fundamental when modified
  2016-10-22  0:15       ` Stefan Huchler
@ 2016-10-23 11:41         ` Michael Heerdegen
  2016-10-23 12:58           ` Stefan Huchler
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Heerdegen @ 2016-10-23 11:41 UTC (permalink / raw)
  To: Stefan Huchler; +Cc: help-gnu-emacs

Stefan Huchler <stefan.huchler@mail.de> writes:

> So did you understand what I wanna do? I can give you the real source
> code not the abstracted here:
>
>
> (defvar kodi-remote-keyboard-mode-map
>   (let ((map (make-sparse-keymap))
> 	(menu-map (make-sparse-keymap)))
> ....
>     (define-key map (kbd "-") 'kodi-remote-volume-decrease)
>     (define-key map (kbd "<tab>") 'kodi-remote-toggle-fullscreen)
>     map)
>   "Keymap for kodi-remote-keyboard-mode.")
>
> (define-derived-mode kodi-remote-keyboard-mode special-mode "kodi-remote-keyboard"
>   "Major mode for remote controlling kodi instance with keyboard commands 
> Key bindings:
> \\{kodi-remote-keyboard-mode-map}"
>   (toggle-read-only)
>   (insert (concat "Kodi Remote:\n"
> 		  (substitute-command-keys
> 		   "\\{kodi-remote-keyboard-mode-map}") ))
>   )
>
> (defun kodi-remote-keyboard ()
>   "Open a `kodi-remote-keyboard-mode' buffer."
>   (interactive)
>   (let* ((name "*kodi-remote-keyboard*")
>          (buffer (or (get-buffer name)
>                      (generate-new-buffer name))))
>     (unless (eq buffer (current-buffer))
>       (with-current-buffer buffer
>         (unless (eq major-mode 'kodi-remote-keyboard-mode)
>           (condition-case e
>               (progn
>                 (kodi-remote-keyboard-mode)
> 		)
>             (error
>              (kill-buffer buffer)
>              (signal (car e) (cdr e))))))
>       (switch-to-buffer-other-window buffer))))

FWIW, works perfectly here.  You should move the `insert' of the mode
definition, however, into `kodi-remote-keyboard', and instead of

   (toggle-read-only)

I think

   (setq buffer-read-only nil)

would be better.


Michael.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: special-mode buffer changes to fundamental when modified
  2016-10-23 11:41         ` Michael Heerdegen
@ 2016-10-23 12:58           ` Stefan Huchler
  2016-10-23 16:24             ` Michael Heerdegen
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Huchler @ 2016-10-23 12:58 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:

> FWIW, works perfectly here.  You should move the `insert' of the mode
> definition, however, into `kodi-remote-keyboard', and instead of

Really so the new buffer shows you the string and if you look into mode
help it does not show you fundamental mode and the keybindings are still
set with kodi...

>    (toggle-read-only)
>
> I think
>
>    (setq buffer-read-only nil)
>
> would be better.

When I change that it says to me:

condition-case: Buffer is read-only: #<killed buffer>

Can you post a exact source you used that did work? maybe my emacs setup
is messed up somehow.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: special-mode buffer changes to fundamental when modified
  2016-10-23 12:58           ` Stefan Huchler
@ 2016-10-23 16:24             ` Michael Heerdegen
  2016-10-23 16:47               ` Stefan Huchler
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Heerdegen @ 2016-10-23 16:24 UTC (permalink / raw)
  To: Stefan Huchler; +Cc: help-gnu-emacs

Stefan Huchler <stefan.huchler@mail.de> writes:

> condition-case: Buffer is read-only: #<killed buffer>

Well, your code behaved differently depending on whether the buffer
already existed or not.

> Can you post a exact source you used that did work? maybe my emacs
> setup is messed up somehow.

Ok, I used the excerpt you posted and edited it very slightly.  There
was indeed a problem: `special-mode', from which your mode derived,
makes the buffer read-only.  So I suggest to bind `inhibit-read-only' to
ignore the read-only flag, since I assume you want the buffer to stay
read-only.

This is the slightly edited example, that indeed works as expected (and
for every call the same):

#+begin_src emacs-lisp
(defvar kodi-remote-keyboard-mode-map
  (let ((map (make-sparse-keymap))
	;; (menu-map (make-sparse-keymap))
        )
    (define-key map (kbd "-") #'kodi-remote-volume-decrease)
    (define-key map (kbd "<tab>") #'kodi-remote-toggle-fullscreen)
    map)
  "Keymap for kodi-remote-keyboard-mode.")

(define-derived-mode kodi-remote-keyboard-mode special-mode "kodi-remote-keyboard"
  "Major mode for remote controlling kodi instance with keyboard commands
Key bindings:
\\{kodi-remote-keyboard-mode-map}")

(defun kodi-remote-keyboard ()
  "Open a `kodi-remote-keyboard-mode' buffer."
  (interactive)
  (let* ((name "*kodi-remote-keyboard*")
         (buffer (get-buffer-create name)))
    (unless (eq buffer (current-buffer))
      (with-current-buffer buffer
        (let ((inhibit-read-only t))
          (erase-buffer)
          (kodi-remote-keyboard-mode)
          (insert (concat "Kodi Remote:\n"
                          (substitute-command-keys
                           "\\{kodi-remote-keyboard-mode-map}"))))
        (switch-to-buffer-other-window buffer)))))
#+end_src


HTH,

Michael.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: special-mode buffer changes to fundamental when modified
  2016-10-23 16:24             ` Michael Heerdegen
@ 2016-10-23 16:47               ` Stefan Huchler
  2016-10-27 16:59                 ` Michael Heerdegen
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Huchler @ 2016-10-23 16:47 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Stefan Huchler <stefan.huchler@mail.de> writes:
>
>> condition-case: Buffer is read-only: #<killed buffer>
>
> Well, your code behaved differently depending on whether the buffer
> already existed or not.

ahh yes I get that now. cause I should done it not in the mode
activation function but the "open-buffer" function makes sense.

that happens if you look over other code and copy to much I guess :)


> Ok, I used the excerpt you posted and edited it very slightly.  There
> was indeed a problem: `special-mode', from which your mode derived,
> makes the buffer read-only.  So I suggest to bind `inhibit-read-only' to
> ignore the read-only flag, since I assume you want the buffer to stay
> read-only.

Yes thats exactly what I want. so I thought let is to define new
temporary varibbales, but in this case you use that to set a value
temporary? so it goes back to its default nil?

thats neat. so basicly you overwrite the buffer wide variable with a
let-scope wide, and after it it falls back to the buffer-wide?

Nice learned something new.

So basicly the straight forward way is right, I just aperently got
unconsistent results because I did the stuff in the mode-activation
function instead the buffer-open function.

Well then I take it back then its not so much a problem of the
documentiation but a mistake on my part.

Still some more example code especialy for special mode would help,
pointing to other modes as example can be problematic, especialy for
elisp noobs that are not so good in understanding the code.

>
> HTH,
>
> Michael.


Thank you very much, then I will soon release a new version of
kodi-remote :)




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: special-mode buffer changes to fundamental when modified
  2016-10-23 16:47               ` Stefan Huchler
@ 2016-10-27 16:59                 ` Michael Heerdegen
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Heerdegen @ 2016-10-27 16:59 UTC (permalink / raw)
  To: Stefan Huchler; +Cc: help-gnu-emacs

Stefan Huchler <stefan.huchler@mail.de> writes:

> Yes thats exactly what I want. so I thought let is to define new
> temporary varibbales, but in this case you use that to set a value
> temporary? so it goes back to its default nil?
>
> thats neat. so basicly you overwrite the buffer wide variable with a
> let-scope wide, and after it it falls back to the buffer-wide?

Yes, you can say so.  Variables defined with `defvar' are always
dynamical, and you can `let'-bind them to steer how functions behave or
what they return, even when the variable does not appear in your code
textually.

> Still some more example code especialy for special mode would help,
> pointing to other modes as example can be problematic, especialy for
> elisp noobs that are not so good in understanding the code.

Writing and maintaining documentation is very work intensive, not every
question is covered.  The things you do are not so noob... and the elisp
source code of Emacs is an excellent source of nice real-life examples.
No doubt, there is a lot to learn, but maybe more help text would not
even be better than learning to read the sources, use the debugger etc
as early as possible, even if this is harder at the beginning.


Regards,

Michael.



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-10-27 16:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-20  2:25 special-mode buffer changes to fundamental when modified Stefan Huchler
2016-10-20 15:33 ` Michael Heerdegen
2016-10-20 16:34   ` Stefan Huchler
2016-10-21 10:58     ` Michael Heerdegen
2016-10-22  0:15       ` Stefan Huchler
2016-10-23 11:41         ` Michael Heerdegen
2016-10-23 12:58           ` Stefan Huchler
2016-10-23 16:24             ` Michael Heerdegen
2016-10-23 16:47               ` Stefan Huchler
2016-10-27 16:59                 ` Michael Heerdegen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.