]> git.bundesbrandschatzamt.de Git - emacsconfig.git/commitdiff
use yasnippets as file templates.
authorAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Mon, 21 Dec 2015 10:19:39 +0000 (11:19 +0100)
committerAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Mon, 21 Dec 2015 10:19:39 +0000 (11:19 +0100)
borrowed from Howard Abrams.

bba.org
templates/default-pl.pl [new file with mode: 0755]
templates/default-sh.sh [new file with mode: 0644]

diff --git a/bba.org b/bba.org
index 9ec51f65f178d9775d171bf74117e9d8cf2b7bca..ecc265e7b1e3b8b2d5d908a3fdef038892762c9b 100644 (file)
--- a/bba.org
+++ b/bba.org
@@ -385,16 +385,25 @@ My first thought: Nice. But do I have a use case? After half a year I
 cannot live without it. I write most of my [[http://www.cfengine.com][CFEngine]] code with
 snippets. Some help for Perl and even for org-mode.
 Thought about using snippets for shell-mode and eshell-mode?
-
+=ha-autoinsert-yas-expand= copied from Howard Abrams.
 #+BEGIN_SRC emacs-lisp
   (add-to-list 'load-path
                "~/.emacs.d/elpa/yasnippet-20150415.244")
   (require 'yasnippet)
   (setq yas-snippet-dirs '("~/.emacs.d/snippets"))
   (yas-global-mode 1)
+  (auto-insert-mode 1)
+  (setq auto-insert-directory "~/.emacs.d/templates")
   (define-key global-map "\C-cy" 'yas-insert-snippet)
     (if (>= emacs-major-version 24)
         (add-to-list 'yas-prompt-functions 'yas-shk-helm-prompt))
+  (defun ha-autoinsert-yas-expand()
+    "Replace text in yasnippet template."
+    (yas-expand-snippet (buffer-string) (point-min) (point-max)))
+  (define-auto-insert "\\.sh$" ["default-sh.sh" ha-autoinsert-yas-expand])
+  (define-auto-insert "\\.pl$" ["default-pl.pl" ha-autoinsert-yas-expand])
+
+
 #+END_SRC
 
 From http://emacswiki.org/emacs/Yasnippet
@@ -490,16 +499,6 @@ Probably the best help to keep track of the not every day used keybindings.
 
 #+END_SRC
 
-* template support
-
-Some default templates for new files are stored in [[templates/]].
-No need to start .pl .sh from scratch.
-
-#+BEGIN_SRC emacs-lisp
-  (require 'template)
-  (template-initialize)
-#+END_SRC
-
 * thesaurus
 
 #+BEGIN_SRC emacs-lisp
diff --git a/templates/default-pl.pl b/templates/default-pl.pl
new file mode 100755 (executable)
index 0000000..de51218
--- /dev/null
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Getopt::Long;
+use Pod::Usage;
+
+my %params;
+
+=head1 NAME
+
+`( file-name-nondirectory  (buffer-file-name))` -
+
+=head1 DESCRIPTION
+
+$0
+
+=head1 SYNOPSIS
+
+=head1 EXAMPLES
+
+=head1 SUBS
+
+=head2 main
+
+=cut
+
+sub main {
+
+    my $result = GetOptions (
+                            "help|h"           => \$params{help},
+                            "verbose|v"        => \$params{verbose},
+                            "man|m"            => \$params{man}
+                           );
+
+    if ( $params{man} ) { pod2usage( -verbose => 2 ); }
+
+    if ( ! ( $server ) || $params{help} )
+    {
+       pod2usage(1);
+    }
+
+
+}
+
+main();
+
+=head1 AUTHOR
+
+
+`(user-full-name)` <`user-mail-address`>
+
+=head1 LICENSE
+
+This program is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1;
diff --git a/templates/default-sh.sh b/templates/default-sh.sh
new file mode 100644 (file)
index 0000000..9971fa5
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/${1:sh}
+# ----------------------------------------------------------------------
+#  `(upcase (file-name-nondirectory (file-name-sans-extension (buffer-file-name))))`: $0
+# ----------------------------------------------------------------------
+
+  OPT1="default value"   # Setup a default value
+  OPT2=0
+
+  while getopts "d:s" o
+  do  case "$o" in
+      d)  OPT1="$OPTARG";;
+      s)  OPT2=1;;
+      [?])    print >&2 "Usage: \$0 [-s] [-d seplist] file ..."
+          exit 1;;
+      esac
+  done
+  shift $(expr $OPTIND - 1)
+
+# ----------------------------------------------------------------------