unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to create my own mode?
@ 2005-11-17 13:56 Jeckob
  2005-11-17 16:40 ` Pascal Bourguignon
  0 siblings, 1 reply; 6+ messages in thread
From: Jeckob @ 2005-11-17 13:56 UTC (permalink / raw)


Hi, i have written some functions in elisp to get some strings
formated. Now i want to have that only active when i open *.ci
files....how can i do this in elisp?  Here is my code:

(defun pre-process-words (words)
  (loop
     with result = '()
     while words
     do (if (string= ":" (first words))
            (progn
              (push (format "%s %s" (first words) (second words))
result)
              (setf words (cddr words)))
            (progn
              (push (first words) result)
              (setf words (cdr words))))
     finally (return (nreverse result))))

(defun format/align-and-newline ()
  (interactive)
  (let* ((anker (point))
         (start (progn (beginning-of-line) (point)))
         (end   (progn (end-of-line) (point)))
         (line  (buffer-substring start end))
         (words (pre-process-words (split-string line))))
    (setq testpoint (first words))
    (setq doppeltab 57)
    (setq tabFlag 0)
    (setq merker1 0)
    (setq kreuzFlag 0)
    (setq doppelFlag 0)
    (when (position ?+ (first words))
      (progn
	(setq kreuzFlag 1)
	(previous-line 1)
	(beginning-of-line)
	(setq start (point))
	(end-of-line)
	(setq end (point))
	(setq line (buffer-substring start end))
	(next-line 1)
	(beginning-of-line)
	(when (or (position ?: line) (position ?+ line) )
	  (progn
	    (setq doppelFlag 1)
	    (setq start (point))
	    (end-of-line)
	    (setq end (point))
	    (setq line (buffer-substring start end))
	    (setq words (split-string line))
	    (beginning-of-line)
	    (forward-char 1)
	    (setq start (point))
	    (delete-region start end)
	    (move-to-column 59 t)
	    (insert (format "%-17s" (second words)))
	    (insert "\n")
	    ))
	(when (= doppelFlag 0)
	  (progn
	    (end-of-line)
	    (insert "\n")
	    ))))
    (when (= kreuzFlag 0)
      (progn
	(if (setq posDoppel (position ?: line) )
	    (if (position ?. testpoint)
		(insert "\n")
	      (delete-region start end)
	      (insert (format "%-10s" (first words)))
	      (setq wortLaenge (length (first words)))
	      (when (> wortLaenge 9)
		(progn
		  (insert " ")
		  ))
	      (dolist (word (cdr words))
		(if (position ?: word)
		    (progn
		      (if (= tabFlag 0)
			  (progn
			    (when (> merker1 doppeltab)
			      (progn
				(setq doppeltab merker1)
				))
			    (move-to-column doppeltab t)
			    (insert (format "%-17s" word))
			    (setq wortLaenge (length word))
			    (when (> wortLaenge 16)
			      (progn
				(insert " ")
				))
			    (setq tabFlag 1)
			    )
			(progn
			  (insert (format "%-17s" word))
			  (setq wortLaenge (length word))
			  (when (> wortLaenge 16)
			    (progn
			      (insert " ")
			      ))
			  )))
		  (progn
		    (insert (format "%-10s" word))
		    (setq wortLaenge (length word))
		    (when (> wortLaenge 9)
		      (progn
			(insert " ")
			))
		    (setq merker1 (current-column))
		    )))
	      (if (beginning-of-line)
		  (insert "\n")
		(setq anker (point)))
	      ))
	(goto-char anker)
	(when (= tabFlag 1)
	  (progn 
	    (end-of-line)
	    ))
	(insert "\n")
	)))) 

Thanks

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

* Re: How to create my own mode?
  2005-11-17 13:56 How to create my own mode? Jeckob
@ 2005-11-17 16:40 ` Pascal Bourguignon
  2005-11-17 18:04   ` Henrik Enberg
       [not found]   ` <mailman.15669.1132250677.20277.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 6+ messages in thread
From: Pascal Bourguignon @ 2005-11-17 16:40 UTC (permalink / raw)


Jeckob@gmx.net writes:

> Hi, i have written some functions in elisp to get some strings
> formated. Now i want to have that only active when i open *.ci
> files....how can i do this in elisp?  Here is my code:

Perhaps you don't really need a fullfleshed mode.
Adding a hook could be enough:

(add-hook 'find-file-hook
   (lambda ()
      (when (string-match "\\.ci$" (buffer-file-name))
         (local-set-key (kbd "RET")hk (function format/align-and-newline))
         (local-set-key (kbd "C-RET") (function newline)))))


You can still choose a default mode for your .ci files:

(require 'cl)
(push '("\\.ci$" . text-mode) auto-mode-alist) ; or some othe mode adapted 
                                               ; to your data.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Nobody can fix the economy.  Nobody can be trusted with their finger
on the button.  Nobody's perfect.  VOTE FOR NOBODY.

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

* Re: How to create my own mode?
  2005-11-17 16:40 ` Pascal Bourguignon
@ 2005-11-17 18:04   ` Henrik Enberg
       [not found]   ` <mailman.15669.1132250677.20277.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 6+ messages in thread
From: Henrik Enberg @ 2005-11-17 18:04 UTC (permalink / raw)


> From: Pascal Bourguignon <spam@mouse-potato.com>
> Date: Thu, 17 Nov 2005 17:40:19 +0100

> (require 'cl)
> (push '("\\.ci$" . text-mode) auto-mode-alist) ; or some othe mode adapted 

you don't need to require cl for push.

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

* Re: How to create my own mode?
       [not found]   ` <mailman.15669.1132250677.20277.help-gnu-emacs@gnu.org>
@ 2005-11-18 10:23     ` Jeckob
  2005-11-18 15:07       ` Pascal Bourguignon
  0 siblings, 1 reply; 6+ messages in thread
From: Jeckob @ 2005-11-18 10:23 UTC (permalink / raw)


Thanks you all and especialy Pascal,
you are really a helpful person...thanks again.

Can you explain me the following line you wrote to me:
        (local-set-key (kbd "C-RET") (function newline)))))

why do you use C-RET to call newline ???

sorry, but tryin to understand every piece of code. 
Thanks

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

* Re: How to create my own mode?
  2005-11-18 10:23     ` Jeckob
@ 2005-11-18 15:07       ` Pascal Bourguignon
  2005-11-21 11:12         ` Jeckob
  0 siblings, 1 reply; 6+ messages in thread
From: Pascal Bourguignon @ 2005-11-18 15:07 UTC (permalink / raw)


Jeckob@gmx.net writes:

> Thanks you all and especialy Pascal,
> you are really a helpful person...thanks again.
>
> Can you explain me the following line you wrote to me:
>         (local-set-key (kbd "C-RET") (function newline)))))
>
> why do you use C-RET to call newline ???

because you want to use RET to call format/align-and-newline.  So when
you'll type RET, you get your formating, and if you want to insert a
newline without any formating you'd have to type: C-q C-j 
but I think it'll be easier to type C-RET.  

[ and of course, you'll have removed the "hk" characters; sometimes my
  iBook keyboard doesn't realize I'm pressing the control key :-( ]

         (local-set-key (kbd "RET")hk (function format/align-and-newline))
-->      (local-set-key (kbd "RET")   (function format/align-and-newline))

> sorry, but tryin to understand every piece of code. 
> Thanks


-- 
"Specifications are for the weak and timid!"

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

* Re: How to create my own mode?
  2005-11-18 15:07       ` Pascal Bourguignon
@ 2005-11-21 11:12         ` Jeckob
  0 siblings, 0 replies; 6+ messages in thread
From: Jeckob @ 2005-11-21 11:12 UTC (permalink / raw)


Ok, got it. Thanks again...

Maybe u can give me some hint on another Emacs Problem? I already
posted a thread for this problem but nobody could give me a proper
answer. So here is my Problem:

If i activate these custom-set-variables

 '(scroll-margin 4)
 '(scroll-preserve-screen-position t)
 '(scroll-step 1)

and restart my emacs, everything is fine! At the top an the bottom of
the page i have a margin set to four lines ant the text scrolls line by
line...But if i set the following custom-set-faces and activate my
hl-line-mode, i get problems

 '(my-highlight-line ((t (:inherit highlight :background "MidnightBlue"
:foreground "White" :box (:line-width 1 :color "grey75")))

Scrolling at the top and bottom is no more line by line, but jumps half
of the page to center again...disabling hl-line-mode brings back the
normal behaviour. Wrote also a thread to gnu.emacs.bug  but got no
reply from them...

Sorry for my bad english, but im not a native speaker....thanks

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

end of thread, other threads:[~2005-11-21 11:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-17 13:56 How to create my own mode? Jeckob
2005-11-17 16:40 ` Pascal Bourguignon
2005-11-17 18:04   ` Henrik Enberg
     [not found]   ` <mailman.15669.1132250677.20277.help-gnu-emacs@gnu.org>
2005-11-18 10:23     ` Jeckob
2005-11-18 15:07       ` Pascal Bourguignon
2005-11-21 11:12         ` Jeckob

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).