From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Leo Liu Newsgroups: gmane.emacs.bugs Subject: bug#14285: 24.3; New octave feature: octave-update-function-file-comment Date: Sat, 27 Apr 2013 16:14:26 +0800 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1367050596 26879 80.91.229.3 (27 Apr 2013 08:16:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 27 Apr 2013 08:16:36 +0000 (UTC) Cc: John Eaton , Jordi =?UTF-8?Q?Guti=C3=A9rrez?= Hermoso To: 14285@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Apr 27 10:16:40 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UW0JD-0000F5-25 for geb-bug-gnu-emacs@m.gmane.org; Sat, 27 Apr 2013 10:16:39 +0200 Original-Received: from localhost ([::1]:45670 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UW0JC-0007jZ-98 for geb-bug-gnu-emacs@m.gmane.org; Sat, 27 Apr 2013 04:16:38 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:47060) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UW0J7-0007jI-8K for bug-gnu-emacs@gnu.org; Sat, 27 Apr 2013 04:16:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UW0J5-00063q-Oc for bug-gnu-emacs@gnu.org; Sat, 27 Apr 2013 04:16:33 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:41897) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UW0J5-00063k-Ld for bug-gnu-emacs@gnu.org; Sat, 27 Apr 2013 04:16:31 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UW0Ic-0002PT-Gq; Sat, 27 Apr 2013 04:16:21 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Leo Liu Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: jordigh@octave.org, jwe@octave.org, monnier@iro.umontreal.ca, bug-gnu-emacs@gnu.org Resent-Date: Sat, 27 Apr 2013 08:16:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 14285 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: "Jordi =?UTF-8?Q?Guti=C3=A9rrez?= Hermoso" , John Eaton , Stefan Monnier Original-Received: via spool by submit@debbugs.gnu.org id=B.13670505039133 (code B ref -1); Sat, 27 Apr 2013 08:16:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 27 Apr 2013 08:15:03 +0000 Original-Received: from localhost ([127.0.0.1]:46004 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UW0Ha-0002Mk-Rv for submit@debbugs.gnu.org; Sat, 27 Apr 2013 04:15:01 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:35349) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UW0HT-0002MQ-75 for submit@debbugs.gnu.org; Sat, 27 Apr 2013 04:14:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UW0HM-0005Yn-Bm for submit@debbugs.gnu.org; Sat, 27 Apr 2013 04:14:45 -0400 Original-Received: from lists.gnu.org ([208.118.235.17]:55235) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UW0HM-0005Yj-8T for submit@debbugs.gnu.org; Sat, 27 Apr 2013 04:14:44 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:46699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UW0HK-0006kY-G2 for bug-gnu-emacs@gnu.org; Sat, 27 Apr 2013 04:14:44 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UW0HI-0005YJ-MX for bug-gnu-emacs@gnu.org; Sat, 27 Apr 2013 04:14:42 -0400 Original-Received: from mail-pb0-x22c.google.com ([2607:f8b0:400e:c01::22c]:59303) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UW0HI-0005YA-Cs for bug-gnu-emacs@gnu.org; Sat, 27 Apr 2013 04:14:40 -0400 Original-Received: by mail-pb0-f44.google.com with SMTP id wz17so1394157pbc.31 for ; Sat, 27 Apr 2013 01:14:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:subject:x-debbugs-cc:date:message-id :mime-version:content-type; bh=J0M/hSGbvrS3YnSnP3tK8G70HMUVuv6RxUzt+DCS8Eo=; b=A+fE/tAydyS+pd/X3OWbLskn47HVYzqd3WkHc4WlKPAmCjzBRZX0U1Y/XXW/A1xKPp DAukGgEzVhqzIfV93hGfBRpW0iJeFcnhopWwd/yAjau+MCcebEzictt/xYOYNxwPZfSp uf67zN39G3T0WAfT+6LIWd0/kUm4TNV84Qq+YHnaonELXYScz5bvAy31nMASLPSVZHlY 1j2cQ8AoEKzenrIknfwntFxaN9xCJN5i6AI0Vr1RluhhicpKD+vlm6fmavjYaodZssJr mYoSsPe8DshQbdQ2vJRg+OOuYm4ltwk9+qH3QEjVlQ1ZXpbZqCJFho5B3OwwAMNiUEDo BVdA== X-Received: by 10.66.248.40 with SMTP id yj8mr29772964pac.95.1367050479481; Sat, 27 Apr 2013 01:14:39 -0700 (PDT) Original-Received: from Zeuss-MacBook.local ([110.172.225.137]) by mx.google.com with ESMTPSA id vb8sm15036247pbc.11.2013.04.27.01.14.37 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 27 Apr 2013 01:14:38 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:73766 Archived-At: --=-=-= Content-Type: text/plain Hello Stefan, JordiGH and John, Based on our discussion on #octave and email, I have made a patch for review. For convenience octave.el with the patch applied is available from http://bpaste.net/raw/94528/. Note Emacs 24.3 is required. The new command octave-update-function-file-comment let users update the doc-string/doc-comment (per octave's definition) to the function name. I am only just beginning octave. So please help test and review the patch. Thanks. Leo --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=patch.diff Content-Description: patch.diff diff --git a/lisp/files.el b/lisp/files.el index 80166961..59eef757 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -4451,7 +4451,8 @@ (defvar auto-save-hook nil "Normal hook run just before auto-saving.") (defcustom before-save-hook nil - "Normal hook that is run before a buffer is saved to its file." + "Normal hook that is run before a buffer is saved to its file. +Any error from the hook prevents saving the buffer." :options '(copyright-update time-stamp) :type 'hook :group 'files) diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el index f8b9e4f6..8a8a6616 100644 --- a/lisp/progmodes/octave.el +++ b/lisp/progmodes/octave.el @@ -32,6 +32,7 @@ ;; information on usage and customization. ;;; Code: +(eval-when-compile (require 'cl-lib)) (require 'comint) (defgroup octave nil @@ -1010,25 +1011,103 @@ (defun octave-maybe-insert-continuation-string () (delete-horizontal-space) (insert (concat " " octave-continuation-string)))) +(defun octave-function-file-p () + "Return non-nil if the first token is \"function\". +The value is (START END NAME-START NAME-END) of the function." + (save-excursion + (goto-char (point-min)) + (when (equal (funcall smie-forward-token-function) "function") + (forward-word -1) + (let* ((start (point)) + (end (progn (forward-sexp 1) (point))) + (name (when (progn + (goto-char start) + (re-search-forward octave-function-header-regexp + end t)) + (list (match-beginning 3) (match-end 3))))) + (cons start (cons end name)))))) + +;; Like forward-comment but stop at non-comment blank +(defun octave-skip-comment-forward (limit) + (and (comment-beginning) + (goto-char (comment-beginning))) + (goto-char (or (comment-search-forward limit t) (point))) + (while (and (< (point) limit) (looking-at-p "\\s<")) + (forward-comment 1))) + +;;; First non-copyright comment block +(defun octave-function-file-comment () + "Beginnning and end positions of the function file comment." + (save-excursion + (goto-char (point-min)) + (let ((bound (progn (forward-comment (point-max)) (point)))) + (goto-char (point-min)) + ;; Copyright block: octave/libinterp/parse-tree/lex.ll around line 1634 + (when (save-excursion + (comment-search-forward bound t) + (when (eq (char-after) ?\{) ; case of block comment + (forward-char 1)) + (skip-syntax-forward "-") + (let ((case-fold-search t)) + (looking-at-p "\\(?:copyright\\|author\\)\\_>"))) + (octave-skip-comment-forward bound)) + (let ((beg (comment-search-forward bound t))) + (when beg + (goto-char beg) + (octave-skip-comment-forward bound) + (list beg (point))))))) + (defun octave-sync-function-file-names () "Ensure function name agree with function file name. See Info node `(octave)Function Files'." (interactive) + (when buffer-file-name + (with-demoted-errors + (cl-destructuring-bind (&optional start _end name-start name-end) + (octave-function-file-p) + (when (and start name-start) + (let ((func (buffer-substring name-start name-end)) + (file (file-name-sans-extension + (file-name-nondirectory buffer-file-name)))) + (save-excursion + (when (and (not (equal file func)) + (progn + (goto-char name-start) + (yes-or-no-p + "Function name different from file name. Fix? "))) + (delete-region name-start name-end) + (insert file))))))))) + +(defun octave-update-function-file-comment (beg end &optional no-query) + "Update function file comment between BEG and END." + (interactive + (progn + (barf-if-buffer-read-only) + (if (use-region-p) + (list (region-beginning) (region-end) current-prefix-arg) + (append (or (octave-function-file-comment) + (error "No function file comment found")) + (list current-prefix-arg))))) (save-excursion - (when (and buffer-file-name - (prog2 - (goto-char (point-min)) - (equal (funcall smie-forward-token-function) "function") - (forward-word -1))) - (let ((file (file-name-sans-extension - (file-name-nondirectory buffer-file-name))) - (func (and (re-search-forward octave-function-header-regexp nil t) - (match-string 3)))) - (when (and func - (not (equal file func)) - (yes-or-no-p - "Function name different from file name. Fix? ")) - (replace-match file nil nil nil 3)))))) + (let* ((bounds (or (octave-function-file-p) + (error "Not in a function file buffer"))) + (func (if (cddr bounds) + (apply #'buffer-substring (cddr bounds)) + (error "Function name not found"))) + (old-func (progn + (goto-char beg) + (when (and (re-search-forward "usage:\\|@deftypefn" end t) + (re-search-forward + "[=}]\\s-*\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" + (line-end-position) t)) + (match-string 1)))) + (old-func (read-string + (format (if old-func "From (default %s): " "From: ") + old-func) + nil nil old-func))) + (when (and func old-func (not (equal func old-func))) + (perform-replace old-func func + (not no-query) nil 'delimited nil nil beg end))))) ;;; Indentation @@ -1356,10 +1435,11 @@ (define-skeleton octave-insert-defun (t (concat vals " = "))) name args)) - \n "function " > str \n \n - octave-block-comment-start "usage: " str \n - octave-block-comment-start \n octave-block-comment-start - \n _ \n + \n octave-block-comment-start "usage: " str \n + octave-block-comment-start \n + octave-block-comment-start \n + "function " > str \n + _ \n "endfunction" > \n) ;;; Communication with the inferior Octave process --=-=-=--