unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Make command available accordnig to major mode
@ 2024-04-02 11:44 Heime
  2024-04-02 16:20 ` Heime
  2024-04-03 11:23 ` Michael Albinus
  0 siblings, 2 replies; 5+ messages in thread
From: Heime @ 2024-04-02 11:44 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

I have a file gali.el and want to be able to call the command 
gali-bash only when I am in sh-mode.  What can I do.

;; ----------------------------------------------------

File bovu/bovu-bash.el

(defconst bovu-bash-func
  "FCNAME ()
 {
  ACTN
 }")

(provide 'bovu-bash)

;; -------------------------------------------------------

File gali.el

(defun gali-bash (actm)
  (interactive)
  (insert bovu-bash-func))



Sent with Proton Mail secure email.



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

* Re: Make command available accordnig to major mode
  2024-04-02 11:44 Make command available accordnig to major mode Heime
@ 2024-04-02 16:20 ` Heime
  2024-04-03 11:23 ` Michael Albinus
  1 sibling, 0 replies; 5+ messages in thread
From: Heime @ 2024-04-02 16:20 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

Have different files that are to be used according to the specific 
major mode (avus-elisp, avus-bash) of the file I am working on.

I made the following inside a minor-mode named gali-minor-mode.

What can I do so that when a bash file gets loaded, I get the functionality
provided by avus-bash when I enable gali-minor-mode

(defun gali-avus ()
  "Require libraries based on major mode."
  (interactive)

  (cond

    ( (or (eq major-mode 'lisp-interaction-mode)
          (eq major-mode 'emacs-lisp-mode))
        (require 'avus-elisp) )

    ( (eq major-mode 'sh-mode)
        (require 'avus-bash) ) ))




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

* Re: Make command available accordnig to major mode
  2024-04-02 11:44 Make command available accordnig to major mode Heime
  2024-04-02 16:20 ` Heime
@ 2024-04-03 11:23 ` Michael Albinus
  2024-04-03 12:00   ` Heime
  1 sibling, 1 reply; 5+ messages in thread
From: Michael Albinus @ 2024-04-03 11:23 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

Heime <heimeborgia@protonmail.com> writes:

Hi,

> I have a file gali.el and want to be able to call the command
> gali-bash only when I am in sh-mode.  What can I do.
>
> ;; ----------------------------------------------------
>
> File bovu/bovu-bash.el
>
> (defconst bovu-bash-func
>   "FCNAME ()
>  {
>   ACTN
>  }")
>
> (provide 'bovu-bash)
>
> ;; -------------------------------------------------------
>
> File gali.el
>
> (defun gali-bash (actm)
>   (interactive)
>   (insert bovu-bash-func))

(defun gali-bash (actm)
  (interactive nil 'sh-mode)
  (insert bovu-bash-func))

Best regards, Michael.



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

* Re: Make command available accordnig to major mode
  2024-04-03 11:23 ` Michael Albinus
@ 2024-04-03 12:00   ` Heime
  2024-04-03 12:14     ` Michael Albinus
  0 siblings, 1 reply; 5+ messages in thread
From: Heime @ 2024-04-03 12:00 UTC (permalink / raw)
  To: Michael Albinus; +Cc: Heime via Users list for the GNU Emacs text editor



On Wednesday, April 3rd, 2024 at 11:23 PM, Michael Albinus <michael.albinus@gmx.de> wrote:

> Heime heimeborgia@protonmail.com writes:
> 
> 
> Hi,
> 
> > I have a file gali.el and want to be able to call the command
> > gali-bash only when I am in sh-mode. What can I do.
> > 
> > ;; ----------------------------------------------------
> > 
> > File bovu/bovu-bash.el
> > 
> > (defconst bovu-bash-func
> > "FCNAME ()
> > {
> > ACTN
> > }")
> > 
> > (provide 'bovu-bash)
> > 
> > ;; -------------------------------------------------------
> > 
> > File gali.el
> > 
> > (defun gali-bash (actm)
> > (interactive)
> > (insert bovu-bash-func))
> 
> 
> (defun gali-bash (actm)
> (interactive nil 'sh-mode)
> (insert bovu-bash-func))
> 
> Best regards, Michael.

Thank you for the answer. 

Because I have a number of files for each specific mode.

bovu-elisp
bovu-bash
bovu-c
bovu-cpp
bovu-python
bovu-latex
 
Am trying to load the specific file only when needed, using hooks perhaps.
Or are there more convenient ways ?




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

* Re: Make command available accordnig to major mode
  2024-04-03 12:00   ` Heime
@ 2024-04-03 12:14     ` Michael Albinus
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Albinus @ 2024-04-03 12:14 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

Heime <heimeborgia@protonmail.com> writes:

Hi,

>> > File gali.el
>> >
>> > (defun gali-bash (actm)
>> > (interactive)
>> > (insert bovu-bash-func))
>>
>> (defun gali-bash (actm)
>> (interactive nil 'sh-mode)
>> (insert bovu-bash-func))
>
> Thank you for the answer.
>
> Because I have a number of files for each specific mode.
>
> bovu-elisp
> bovu-bash
> bovu-c
> bovu-cpp
> bovu-python
> bovu-latex
>
> Am trying to load the specific file only when needed, using hooks perhaps.
> Or are there more convenient ways ?

If you want to load the file always when you enter a given mode, you can
use the mode specific hooks. Like this (untested):

(defun gali-bash ()
 (require 'avus-bash))

(add-hook 'sh-mode-hook 'gali-bash)

Best regards, Michael.



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

end of thread, other threads:[~2024-04-03 12:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-02 11:44 Make command available accordnig to major mode Heime
2024-04-02 16:20 ` Heime
2024-04-03 11:23 ` Michael Albinus
2024-04-03 12:00   ` Heime
2024-04-03 12:14     ` Michael Albinus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).