emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] add-change-log-entry for orgfiles, header


From: Uwe Brauer
Subject: Re: [O] add-change-log-entry for orgfiles, header
Date: Sat, 15 Oct 2016 09:06:39 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

    > On Friday, 14 Oct 2016 at 16:58, Uwe Brauer wrote:
    > [...]


    > Looking at the vc.el code, there is the following comment which may
    > allow you to accomplish effectively the same thing although in the
    > reverse order (commit and then update changelog)?

    > ;; If your site uses the ChangeLog convention supported by Emacs, the
    > ;; function `log-edit-comment-to-change-log' could prove a useful checkin 
hook,
    > ;; although you might prefer to use C-c C-a (i.e. 
`log-edit-insert-changelog')
    > ;; from the commit buffer instead or to set `log-edit-setup-invert'.

    > (untested)

    > but I may have completely misunderstood your question and, if so,
    > apologies for the noise!


What you propose is exactly the other way around, first vc-next-action
then insert that log message in the ChangeLog file. But ChangeLog files
got more and more unpopular and are omitted in for example GNU emacs,
they are only used as a tool: first add an entry to ChangeLog (since for
lisp it has nice navigation markers), then insert that entry into the
commit message for vc-next-action.

I want to do the same for org files, using their syntax as navigations
references. Here is the addon for latex to make my point clearer.
Of course it contains a lot of auctex/reftex specific stuff.

Uwe




(defun reftex-add-log-current-defun ()
  "Return the current location for add-change-log.
The string will contain information about the section type and title,
the current labeled environment, and the label, if any."

  (reftex-access-scan-info)
;  (debug)
  (save-excursion
    ;; Check if we should move backward into an environment
    (when (and reftex-add-log-use-environment-above
               (save-excursion
                 (re-search-backward "\\\\end{[^} \n\r]+}[ \n\r\t]*\\=" nil t)))
      (goto-char (match-beginning 0)))
    ;; Parse
    (let* ((section-start
            (save-excursion
              (if (re-search-backward reftex-section-regexp nil t)
                  (match-beginning 1)
                nil)))
           (macro (if section-start (match-string 2)))
           (title (if section-start
                      (save-match-data 
                        (save-excursion
                          (goto-char (match-end 0))
                          (reftex-context-substring)))))
           (envs 
            (cond ((eq reftex-add-log-restrict-environments 'label)
                   (delq nil
                         (mapcar (lambda (x)
                                   (if (not (equal (string-to-char (car x)) 
?\\))
                                (car x)))
                          reftex-env-or-mac-alist)))
                  ((eq reftex-add-log-restrict-environments nil) t)
                  ((listp reftex-add-log-restrict-environments)
                   reftex-add-log-restrict-environments)
                  (t t)))
           (env-info (reftex-what-environment envs))
           (env-info (if (listp (car env-info)) (car env-info) env-info))
           (env (if env-info (car env-info)))
           (env-start (if env (cdr env-info)))
           (env-end
            (if env-start
                (save-excursion
                  (goto-char env-start)
                  (if (re-search-forward (concat "\\end{"
                                                 (regexp-quote env)
                                                 "}") nil t)
                      (match-beginning 0)
                    (point-max)))))
           (label
            (if env-start
                (save-excursion
                  (goto-char env-start)
                  (if (re-search-forward "\\label{\\([^}]*\\)}" env-end t)
                      (match-string 1)
                    nil))))
           (rtn reftex-add-log-format))
      
      ;; Cleanup the section title
      (while (string-match "[ \t]*\n[ \t]*" title)
        (setq title (replace-match " " nil nil title)))
      ;; Limit the length of the title
      (cond ((numberp reftex-add-log-shorten-title)
             (let ((n reftex-add-log-shorten-title))
               (if (> (length title) n)
                   (setq title (concat (substring title 0 (- n 3)) "...")))))
            ((eq reftex-add-log-shorten-title 'abbrev)
             (setq title (reftex-abbreviate-title title))))
      ;; Here we put together the context string for add-log.
      ;; The following variables contain useful stuff:
      (while (string-match " " title)
        (setq title (replace-match "_" t t title)))
      
      (while (string-match "%m" rtn)
        (setq rtn (replace-match (or macro "") t t rtn)))
      (while (string-match "%t" rtn)
        (setq rtn (replace-match (or title "") t t rtn)))
      (while (string-match "%e" rtn)
        (setq rtn (replace-match (or env "") t t rtn)))
      (while (string-match "%l" rtn)
        (setq rtn (replace-match (or label "") t t rtn)))
      ;; Return the final string
      rtn)))




reply via email to

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