emacsweblogs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacsweblogs] Re: weblogger & major mode


From: David Abrahams
Subject: [Emacsweblogs] Re: weblogger & major mode
Date: Fri, 18 Sep 2009 14:28:50 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (darwin)

on Thu Sep 17 2009, mah-AT-everybody.org (Mark A. Hershberger) wrote:

> Based on David Abrahams' and Andrea Crotti's feedback, I've put together
> a quick hack to toggle the weblogger-entry buffer between the major mode
> of your choice.

Thanks for working on this, Mark!

> I'd like to see what you guys think before committing this, so I've made
> my changes available at <http://winkyfrown.com/weblogger.el>.

Well, my first thought is "why didn't he use something based on
clone-indirect-buffer and narrow-to-region instead of actually inserting
and removing headers?"  Take a look at my-clone-region-set-mode in the
enclosed.  It somehow seems like a more principled approach.

> Some notes on the use of this:
>
>    * There are three new customizations:
>
>      + weblogger-edit-mode - The major mode to switch to for editing the
>        content.
>      + weblogger-edit-mode-toggle-hook - hook to run when switching to
>        the above mode.
>      + weblogger-weblogger-mode-toggle-hook - hook to run when switching
>        back to weblogger-entry-mode
>
>    * In the weblogger-entry-mode, I've added a keybinding (C-c C-e) to
>      switch to editting the body in the major-mode you put in
>      weblogger-edit-mode (defaults to nxml-mode, but I'm open to
>      suggestions for a better mode).

Nice feature.

>      When you switch major modes this way, the header is removed, the
>      hooks are run and you can edit the body using whatever you're used
>      to.
>
>    * When you want to switch back to edit the meta-data and/or submit
>      the entry, you would do “M-x weblogger-toggle-edit-body RET” and
>      the headers will be inserted back into the buffer and the buffer
>      will be switched back to weblogger-entry-mode.
>
> Let me know what you think!

The only thing I really wanted corrected was that if I edited a clone of
the *weblogger-entry* buffer, its contents would be updated, but somehow
weblogger-entry-mode wouldn't know that it had been changed, so they
could be too easily lost, for example, by `C-c C-n'.  I think I'd still
really like that to be fixed, no matter what else is done.

Thanks!

;;
;; General utilities
;;

(defun my-kill-buffer ()
  "Just kill the current buffer without asking, unless of course it's a
modified file"
  (interactive)
  (kill-buffer (current-buffer)))

(defun my-switch-to-previous-buffer ()
  "Switch to the most recently visited buffer without asking"
  (interactive)
  (switch-to-buffer nil))

(defun my-info-other-frame ()
  (interactive)
  (select-frame (make-frame))
  (info))

(defun my-mark-or-point ()
  "Return the mark if it is active, otherwise the point."
  (if
      (if (fboundp 'region-active-p) (region-active-p) mark-active)
      (mark)
    (point)))

(defun my-selection ()
  "Return a pair [start . finish) delimiting the current selection"
      (let ((start (make-marker))
            (finish (make-marker)))
        (set-marker start (min (my-mark-or-point) (point)))

        (set-marker finish (max (my-mark-or-point) (point)))
        (cons start finish)))

(defun my-replace-in-region (start finish key replacement)
  "In the range [START, FINISH), replace text matching KEY with REPLACEMENT"
  (goto-char start)
  (while (search-forward key finish t)
    (replace-match replacement)))

(defun my-activate-mark ()
  "Make the mark active if it is currently inactive"
  (set-mark (mark t)))


(defun my-matching-paren (arg)
  (interactive "P")
  (if arg
      () ;;(insert "%")  ; insert the character we're bound to
    (cond ((looking-at "[[({]")
           (forward-sexp 1)
           (forward-char -1))
          ((looking-at "[]})]")
           (forward-char 1)
           (forward-sexp -1))
          (t
           ;; (insert "%")  ; insert the character we're bound to
      ))))

; Something for converting DOS files to unix format
(defun my-use-code-undecided-unix ()
  (interactive)
  (set-buffer-file-coding-system 'undecided-unix)
  (save-buffer))

(defun my-other-window-backward (&optional n)
  "Select the previous window. Copied from \"Writing Gnu Emacs Extensions\"."
  (interactive "P")
  (other-window (- (or n 1)))
  )

; return the first non-nil result of applying f to each element of seq
(defun my-first-non-nil (seq f)
  (and seq
       (or
        (apply f (list (car seq)))
        (my-first-non-nil (cdr seq) f)))
  )

(defun my-mode-read ()
  (let ((symb 'c++-mode)
        (predicate 'commandp)
        (enable-recursive-minibuffers t)
        val)
    (setq val (completing-read
               (concat "Mode "
                       (if symb
                           (format " (default %s)" symb))
                       ": ")
               obarray predicate t nil))
    (list (if (equal val "")
              symb
            (intern val)))))

(defun my-clone-region-set-mode (&optional mode)
  (interactive (my-mode-read))
  (let ((pt (point))(mk (my-mark-or-point)))
    (with-current-buffer (clone-indirect-buffer-other-window "*clone*" t)
    (narrow-to-region pt mk)
    (if mode
        (funcall mode)
      (lisp-mode)))))

(provide 'dwa-util)
-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

reply via email to

[Prev in Thread] Current Thread [Next in Thread]