all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#14112: [patch] add-log-current-defun-function for sh-mode
@ 2013-04-01  8:25 Masatake YAMATO
  2013-04-04  2:03 ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Masatake YAMATO @ 2013-04-01  8:25 UTC (permalink / raw
  To: 14112

This is a feature request with a patch. Please, review the 
patch and install it to the official source tree if appreciated.


The patch comes from two parts:
    1. definition of add-log-current-defun-function for sh-mode
    2. Test case

Mode own add-log-current-defun-function is not defined in sh-mode.
So wc cannot pick up a function name with C-x 4 a.
This patch implement it.

------------------------------------------------------------
revno: 112201
committer: Masatake YAMATO <yamato@redhat.com>
branch nick: emacs-sh-add-log
timestamp: Mon 2013-04-01 17:22:03 +0900
message:
  * lisp/progmodes/sh-script.el (sh-current-defun-name): New function.
  * automated/add-log-tests.el: New file.
diff:
=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2013-04-01 08:13:33 +0000
+++ lisp/ChangeLog	2013-04-01 08:22:03 +0000
@@ -1,5 +1,9 @@
 2013-04-01  Masatake YAMATO  <yamato@localhost.localdomain>
 
+	* progmodes/sh-script.el (sh-current-defun-name): New function.
+
+2013-04-01  Masatake YAMATO  <yamato@localhost.localdomain>
+
 	* progmodes/sh-script.el (sh-imenu-generic-expression): Handle
 	function names with a single character.
 

=== modified file 'lisp/progmodes/sh-script.el'
--- lisp/progmodes/sh-script.el	2013-04-01 08:13:33 +0000
+++ lisp/progmodes/sh-script.el	2013-04-01 08:22:03 +0000
@@ -353,6 +353,29 @@
   :group 'sh-script
   :version "20.4")
 
+
+(defun sh-current-defun-name ()
+  "Find the name of function or variable at point.
+For use in `add-log-current-defun-function'."
+  (save-excursion
+    (end-of-line)
+    (when (re-search-backward
+	   (concat "\\(?:"
+		   ;; function FOO
+		   ;; function FOO()
+		   "^\\s-*function\\s-+\\\([[:alpha:]_][[:alnum:]_]*\\)\\s-*\\(?:()\\)?"
+		   "\\)\\|\\(?:"
+		   ;; FOO()
+		   "^\\s-*\\([[:alpha:]_][[:alnum:]_]*\\)\\s-*()"
+		   "\\)\\|\\(?:"
+		   ;; FOO=
+		   "^\\([[:alpha:]_][[:alnum:]_]*\\)="
+		   "\\)")
+	   nil t)
+      (or (match-string-no-properties 1)
+	  (match-string-no-properties 2)
+	  (match-string-no-properties 3)))))
+
 (defvar sh-shell-variables nil
   "Alist of shell variable names that should be included in completion.
 These are used for completion in addition to all the variables named
@@ -1533,6 +1556,7 @@
   (setq-local skeleton-newline-indent-rigidly t)
   (setq-local defun-prompt-regexp
 	      (concat "^\\(function[ \t]\\|[[:alnum:]]+[ \t]+()[ \t]+\\)"))
+  (setq-local add-log-current-defun-function #'sh-current-defun-name)
   ;; Parse or insert magic number for exec, and set all variables depending
   ;; on the shell thus determined.
   (sh-set-shell

=== modified file 'test/ChangeLog'
--- test/ChangeLog	2013-04-01 08:13:33 +0000
+++ test/ChangeLog	2013-04-01 08:22:03 +0000
@@ -1,5 +1,9 @@
 2013-04-01  Masatake YAMATO  <yamato@redhat.com>
 
+	* automated/add-log-tests.el: New file.
+
+2013-04-01  Masatake YAMATO  <yamato@redhat.com>
+
 	* automated/imenu-tests.el: New file.
 
 2013-03-30  Fabián Ezequiel Gallina  <fabian@anue.biz>

=== added file 'test/automated/add-log-tests.el'
--- test/automated/add-log-tests.el	1970-01-01 00:00:00 +0000
+++ test/automated/add-log-tests.el	2013-04-01 08:22:03 +0000
@@ -0,0 +1,84 @@
+;;; add-log-tests.el --- Test suite for add-log.
+
+;; Copyright (C) 2013 Free Software Foundation, Inc.
+
+;; Author: Masatake YAMATO <yamato@redhat.com>
+;; Keywords: vc tools
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'add-log)
+
+(defmacro add-log-current-defun-deftest (name doc major-mode
+					      content marker expected-defun)
+  "Generate an ert test for mode-own `add-log-current-defun-function'.
+Run `add-log-current-defun' at the point where MARKER specifies in a
+buffer which content is CONTENT under MAJOR-MODE. Then it compares the
+result with EXPECTED-DEFUN."
+  (let ((xname (intern (concat "add-log-current-defun-test-"
+			       (symbol-name name)
+			       ))))
+    `(ert-deftest ,xname ()
+	 ,doc
+       (with-temp-buffer
+	 (insert ,content)
+	 (goto-char (point-min))
+	 (funcall ',major-mode)
+	 (should (equal (when (search-forward ,marker nil t)
+			  (replace-match "" nil t)
+			  (add-log-current-defun))
+			,expected-defun))))))
+
+(add-log-current-defun-deftest
+ sh-func1
+ "Test sh-current-defun-name can find function."
+ sh-mode "
+function foo
+{
+	><
+}" "><" "foo")
+
+(add-log-current-defun-deftest
+ sh-func2
+ "Test sh-current-defun-name can find function."
+ sh-mode "
+foo()
+{
+	><
+}" "><" "foo")
+
+(add-log-current-defun-deftest
+ sh-func3
+ "Test sh-current-defun-name can find function."
+ sh-mode "
+function foo()
+{
+	><
+}" "><" "foo")
+
+(add-log-current-defun-deftest
+ sh-var
+ "Test sh-current-defun-name can find variabe definision."
+ sh-mode "
+PATH=a:/ab:/usr/abc
+DIR=/pr><oc"
+"><" "DIR")
+
+(provide 'add-log-tests)
+
+;;; add-log-tests.el ends here






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

* bug#14112: [patch] add-log-current-defun-function for sh-mode
  2013-04-01  8:25 bug#14112: [patch] add-log-current-defun-function for sh-mode Masatake YAMATO
@ 2013-04-04  2:03 ` Stefan Monnier
  2013-04-05 10:56   ` Masatake YAMATO
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2013-04-04  2:03 UTC (permalink / raw
  To: Masatake YAMATO; +Cc: 14112

> This is a feature request with a patch.  Please, review the
> patch and install it to the official source tree if appreciated.

The patch looks good.  I se you don't yet have write access.
Do you want me to give you access so you can install those
patches yourself?  That would save me time,


        Stefan





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

* bug#14112: [patch] add-log-current-defun-function for sh-mode
  2013-04-04  2:03 ` Stefan Monnier
@ 2013-04-05 10:56   ` Masatake YAMATO
  2013-04-05 13:27     ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Masatake YAMATO @ 2013-04-05 10:56 UTC (permalink / raw
  To: monnier; +Cc: 14112

>> This is a feature request with a patch.  Please, review the
>> patch and install it to the official source tree if appreciated.
> 
> The patch looks good.  

Thank you for reviewing.

> I se you don't yet have write access.
> Do you want me to give you access so you can install those
> patches yourself?  That would save me time,

I don't want take your time for installing my small patch. 
Please, re-give me write access to bzr repository. 
My account is "masatake".

I must learn the usage of bzr.

Masatake YAMATO







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

* bug#14112: [patch] add-log-current-defun-function for sh-mode
  2013-04-05 10:56   ` Masatake YAMATO
@ 2013-04-05 13:27     ` Stefan Monnier
  2013-04-05 14:22       ` Masatake YAMATO
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2013-04-05 13:27 UTC (permalink / raw
  To: Masatake YAMATO; +Cc: 14112

> Please, re-give me write access to bzr repository. 

Great, thank you.
Actually, I can't do that without you first requesting membership in the
"emacs" group from your Savannah account.


        Stefan





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

* bug#14112: [patch] add-log-current-defun-function for sh-mode
  2013-04-05 13:27     ` Stefan Monnier
@ 2013-04-05 14:22       ` Masatake YAMATO
  0 siblings, 0 replies; 5+ messages in thread
From: Masatake YAMATO @ 2013-04-05 14:22 UTC (permalink / raw
  To: monnier; +Cc: 14112

>> Please, re-give me write access to bzr repository. 
> 
> Great, thank you.
> Actually, I can't do that without you first requesting membership in the
> "emacs" group from your Savannah account.
> 
> 
>         Stefan

I've submitted the requesting.
Regard,
Masatake YAMATO





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

end of thread, other threads:[~2013-04-05 14:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-01  8:25 bug#14112: [patch] add-log-current-defun-function for sh-mode Masatake YAMATO
2013-04-04  2:03 ` Stefan Monnier
2013-04-05 10:56   ` Masatake YAMATO
2013-04-05 13:27     ` Stefan Monnier
2013-04-05 14:22       ` Masatake YAMATO

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.