help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Constructing code template systems


From: Jean Louis
Subject: Re: Constructing code template systems
Date: Wed, 19 Oct 2022 07:12:36 +0300
User-agent: Mutt/2.2.7+37 (a90f69b) (2022-09-02)

* Heime <heimeborgia@protonmail.com> [2022-10-19 04:00]:
> ------- Original Message -------
> On Wednesday, October 19th, 2022 at 12:17 AM, John Haman <mail@johnhaman.org> 
> wrote:
> 
> 
> > On 10/17/22 6:36 PM, Heime via Users list for the GNU Emacs text editor
> > wrote:
> > 
> > > code template systems
> > 
> > 
> > Like macros?
> 
> Do not know what emacs calls them.
> 
> Basically rather than writing the following, I just press some text,
> and the section of code gets inserted for me. 
> 
> (:documentation (concat "DECSTR.\n\n" DETAILS))


Evaluate following to get into section explaining about skeletons:

(info "(autotype) Top")




I often use this one:
---------------------


(define-skeleton with-tabulated-id
  "Helper skeleton for `tabulated-list-get-id'"
  nil
  "(defun " (skeleton-read "Function name: ") " (" (skeleton-read "Arguments: " 
"&optional id") ")
  \"\"
  (interactive)
  (when-tabulated-id \"" (skeleton-read "Table: ") "\"
     ))")


Or I use this one to generate necessary SQL:
--------------------------------------------

(define-skeleton cf-sql-table
    "Prepare the SQL table for Central Files database design."
  nil
  "
-- ------------------------------------------
-- ------------ Table " (setq table (skeleton-read "Table name: ")) "
-- ------------------------------------------
DROP SEQUENCE " table "_id_seq;

CREATE TABLE " table " (
" table "_id INTEGER GENERATED BY DEFAULT AS IDENTITY,
" table "_uuid UUID NOT NULL DEFAULT gen_random_uuid(),
" table "_datecreated TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
" table "_datemodified TIMESTAMP,
" table "_usercreated TEXT NOT NULL DEFAULT current_user,
" table "_usermodified TEXT NOT NULL DEFAULT current_user,
" table "_name TEXT,
" table "_description TEXT,
" table "_ TEXT
);
GRANT ALL ON " table " TO PUBLIC;
DROP VIEW " table "_combo;
CREATE OR REPLACE VIEW " table "_combo AS
SELECT " table "_id AS id,
" table "_name AS TEXT
FROM " table ";
GRANT SELECT ON " table "_combo TO PUBLIC;
COMMENT ON TABLE " table " IS '" (capitalize table) "';
COMMENT ON COLUMN " table "." table "_id IS 'ID';
COMMENT ON COLUMN " table "." table "_uuid IS 'UUID';
COMMENT ON COLUMN " table "." table "_datecreated IS 'Date created';
COMMENT ON COLUMN " table "." table "_datemodified IS 'Date modified';
COMMENT ON COLUMN " table "." table "_usercreated IS 'User created';
COMMENT ON COLUMN " table "." table "_usermodified IS 'User modified';
COMMENT ON COLUMN " table "." table "_name IS 'Name';
COMMENT ON COLUMN " table "." table "_description IS 'Description';
COMMENT ON COLUMN " table "." table "_IS '';

CREATE UNIQUE INDEX " table "_index ON " table " ( " table "_name );

-- INSERT INTO " table " (" table "_name) VALUES ('');
-- INSERT INTO meta_tables VALUES ('" table "', 'hide', '1');

-- Triggers
-- For Date Modified
CREATE TRIGGER " table "_moddatetime
BEFORE UPDATE ON " table "
FOR EACH ROW
EXECUTE PROCEDURE moddatetime(" table "_datemodified);

-- For User Modified
CREATE TRIGGER insert_username_" table "
BEFORE INSERT OR UPDATE ON " table "
FOR EACH ROW
EXECUTE PROCEDURE insert_username(" table "_usermodified);

")



-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

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