Difference between pages "Emacs" and "Zope HOWTO"

From Funtoo
(Difference between pages)
Jump to: navigation, search
 
m
 
Line 1: Line 1:
[[File:emacs-logo.png]]
+
This page documents how to use Zope with Funtoo Experimental, which currently has good Zope support thanks to [[Progress Overlay Python]] integration.
  
Emacs is a famous text editor, famous by its flexibility and extensibility.  One manual describes it as "the extensible, customizable, self-documenting, real-time display editor".
+
== About Zope ==
  
This page is designed to give users a good place to share their config and settings for a nice emacs setup.
+
Zope is an Open Source application server framework written in Python. It has an interesting history which you should familiarize yourself with before starting Zope development, as it contains several interesting twists and turns.
  
== Installing emacs ==
+
=== Zope History ===
To install {{Package|app-editors/emacs}}, run the following command:
+
<console>
+
###i## emerge -av emacs
+
</console>
+
for the standard gnu emacs {{Package|app-editors/xemacs}} and
+
<console>
+
###i## emerge -av xemacs
+
</console>
+
  
for the 1980 created fork of emacs, both should handle the same, while emacs on its own stands here for both. If you install additional extensions for both you might need to add <tt>app-emacs</tt> or <tt>app-xemacs</tt> to the package as there are two different versions for both.
+
{{Note}} This HOWTO targets Zope 2.13, which includes Five. It is typically the version you should be using for new Zope projects.
  
== What emacs is and what it is not ==
+
* There are two versions of Zope, Zope 2 and Zope 3. One might assume that Zope 3 is the version that people should use for new software development projects by default, but this is not the case. Most Zope-based projects continue to use Zope 2. Zope 3 was an attempt to redesign Zope 2 from scratch, and is completely different from Zope 2, but it was not adopted by the community.
  
# Emacs is primarily a text editor and not a word processor, it concentrates on manipulating any kind of text, rather than manipulating the font and look. It is client and GUI based, so can be used on local box in graphical environments with a GUI and remote on a server in a client mode.  
+
* There is also something called [http://codespeak.net/z3/five/ Five] (named because it is "2 + 3") that backports many of the new features of Zope 3 into the Zope 2 framework. Several projects will use Zope 2 plus Five in order to use some of the newer features in Zope. Five was merged into mainline Zope 2 in early 2010, and first appeared in Zope 2.8.
# Emacs provides commands for manipulate every kind of text and syntax highlighting.
+
  
=== Customizability ===
+
* You can learn more about the history of Zope 2, 3 and Five in the [http://svn.zope.org/Zope/trunk/src/Products/Five/README.txt?view=markup Five README].
  
'''Emacs is highly customizable:'''
+
* To make things even more interesting, work on [http://docs.zope.org/zope2/releases/4.0/ Zope 4] is underway, and it will be based on 2.13 rather than 3.x. It includes a number of [http://docs.zope.org/zope2/releases/4.0/CHANGES.html#restructuring incompatible changes] with prior versions.
 +
=== Zope Resources ===
  
* the <tt>customize</tt> extension, which allows settings of customized variables, such as color themes, graphical interface, etc. This part is intended for emacs beginners, who do not want to work with Emacs lisp code.
+
Now that you understand what version of Zope you should be targeting (2.13), we can point you towards the correct documentation :)
* combine keystrokes to execute complex makros.
+
* using Emacs Lisp. Designed for the emacs professional.
+
  
=== Extensibility ===
+
; [http://docs.zope.org/zope2/zope2book/ The Zope 2 Book]: This book provides a general introduction to Zope concepts and ZMI. It is a good place to start, but doesn't provide a direct introduction to Zope development. It's recommended that you skim through this book to familiarize yourself with Zope. It generally does not assume much prior knowledge about Web development or Python.
 +
; [http://docs.zope.org/zope2/zdgbook/ Zope Developer's Guide]: This guide will give you a better introduction to Zope development. It assumes you already know Python. Skip chapters 1 and 2 and start in [http://docs.zope.org/zope2/zdgbook/ComponentsAndInterfaces.html chapter 3], which covers components and interfaces. [http://docs.zope.org/zope2/zdgbook/Products.html Chapter 5] covers the creation of your first product.
 +
; Five: We're not done yet. There is a bunch of stuff in Zope 2.13 that is not in the official documentation. Namely, the stuff in Five. Check out [http://codespeak.net/z3/five/manual.html The Five Manual].
 +
; ZTK: [http://docs.zope.org/ztkpackages.html ZTK Documentation]
 +
; ZCA: [http://www.muthukadan.net/docs/zca.html A Comprehensive Guide to Zope Component Architecture] offers a good introduction to the programming concepts of ZCA. We also have a new page on [[Zope Component Architecture]] which will help you to understand the big picture of ZCA and why it is useful. ZCML ("Z-camel") is a part of ZCA and  was introduced in Zope 3, so typically you will find ZCML documented within Zope 3 documentation and book.
 +
; Content Components: Views and Viewlets: [http://docs.zope.org/zope.viewlet/index.html This tutorial on viewlets] also contains some viewlet-related ZCML examples near the end. The "Content Component way" of developing in Zope seems to be a Zope 3 thing and tied to ZCML. Chapter 13+ of Stephan Richter's ''Zope 3 Developer's Handbook'' (book) seems to cover this quite well. You will probably also want to check out Philipp Weitershausen's ''Web Component Development with Zope 3'' (book).
 +
; [http://wiki.zope.org/zope2/Zope2Wiki Zope 2 Wiki]: Main wiki page for all things related to Zope 2.
 +
; [http://docs.zope.org docs.zope.org]: This is the main site for Zope documentation.
  
As a result of the above points, Emacs behaviour can be easily definied to all text behavings without limit. Like some of the examples below show you:
+
== First Steps ==
  
* AUCTeX, A suite for LaTeX and other TeX versions,
+
First, you will need to emerge {{Package|net-zope/zope}}:
* ERC, A Emacs IRC client,
+
* ORG-mode, A Emacs PIM and Orga tool
+
* Wanderlust, A highly flexible Mail tool for Emacs
+
  
== User Configs ==
 
=== golodhrim's config ===
 
==== .emacs ====
 
 
<console>
 
<console>
###i## nano ~/.emacs
+
# ##i## emerge -av zope
;;;;;;;;;;;;;;;;;;;;;;
+
</console>
;; General Settings ;;
+
;;;;;;;;;;;;;;;;;;;;;;
+
  
(setq emacs-root-dir (concat (getenv "HOME") "/em/"))
+
Zope is now installed.
  
(setq inhibit-startup-message t)    ;; Suppress the startup message
+
== Project Skeleton ==
(setq standard-indent 4)            ;; Default indent level is 3 chars
+
(setq-default indent-tabs-mode nil) ;; Indent with spaces, not tabs
+
  
(setq make-backup-files nil)          ;; Enable backup files.
+
{{Note}} Zope should be run by a regular user account, not as the root user.
(setq version-control nil)            ;; Enable versioning with default values
+
(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))  ;; Save all backup file in this directory.
+
  
(line-number-mode 1)                ;; Show line-number in the mode line
+
The first step in using Zope is to ensure that you are using a regular user account. Create a new directory called ''<tt>zope_test</tt>'':
(column-number-mode 1)              ;; Show column-number in the mode line
+
<console>
 +
$##bl## cd
 +
$##bl## mkdir zope_test
 +
</console>
  
(setq auto-fill-mode 1)            ;; Line wrap
+
Now, enter the directory, and create an "instance", which is a set of files and directories that are used to contain a Zope project:
 +
<console>
 +
$##bl## cd zope_test
 +
$##bl## /usr/lib/zope-2.13/bin/mkzopeinstance
 +
</console>
  
(set-default-font "Inconsolata-12")
+
You will see the following output, and will be prompted to answer a few questions:
 +
<console>
 +
Please choose a directory in which you'd like to install
 +
Zope "instance home" files such as database files, configuration
 +
files, etc.
  
(setq browse-url-browser-function 'browse-url-generic
+
Directory: instance
      browse-url-generic-program "google-chrome")
+
Please choose a username and password for the initial user.
 +
These will be the credentials you use to initially manage
 +
your new Zope instance.
  
(global-set-key (kbd "C-<prior>") 'previous-buffer)
+
Username: admin
(global-set-key (kbd "C-<next>" ) 'next-buffer    )
+
Password: ****
 +
Verify password: ****
 +
</console>
  
 +
Now, we will start our Zope instance:
 +
<console>
 +
$##bl## cd instance
 +
$##bl## bin/runzope
 +
</console>
  
(setq load-path (cons "~/.emacs.d/plugins" load-path))
+
Now that Zope is running, you can visit ''<tt>localhost:8080</tt>'' in your Web browser. You will see a nice introductory page to Zope.
  
(setq global-font-lock-mode 1)
+
If you now go to the ''<tt>localhost:8080/manage</tt>'' URL, you will be prompted to log in. Enter the username and password you specified. You are now logged in to the ZMI (Zope Management Interface.)
  
(show-paren-mode 1)
+
You can stop your application by pressing Control-C. In the future, you can start and stop your Zope instance using the following commands:
  
;;;;;;;;;;;;;;;;;;
+
<console>
;; el-get setup ;;
+
$##bl## zopectl start
;;;;;;;;;;;;;;;;;;
+
$##bl## zopectl stop
(add-to-list 'load-path "~/.emacs.d/el-get/el-get")
+
</console>
(unless (require 'el-get nil t)
+
  (with-current-buffer
+
    (url-retrieve-synchronously "https://raw.github.com/golodhrim/el-get/master/el-get-install.el")
+
  (end-of-buffer)
+
  (eval-print-last-sexp)))
+
  
(el-get 'sync)
+
{{Note}} ''<tt>zopectl start</tt>'' will cause your instance to run in the background rather than consuming a shell console.
  
;;;;;;;;;;;;;;;
+
== First Project ==
;; mediawiki ;;
+
;;;;;;;;;;;;;;;
+
(require 'mediawiki)
+
  
;;;;;;;;;;;;;;;;;;;;
+
We will create a single very primitive Zope package, consisting of an Interface for a TODO class, and a TODO class.
;; Org-mode stuff ;;
+
;;;;;;;;;;;;;;;;;;;;
+
  
;; Tell emacs where org-mode is
+
Create the following files and directories relative to your project root:
;;(setq load-path (cons "/usr/share/emacs/site-lisp/org-mode/" load-path))
+
;;(setq load-path (cons "/usr/share/emacs/site-lisp/org-mode/contrib/" load-path))
+
(require 'org-install) ;; Tell emacs to use org-mode
+
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode)) ;; Turn on org-mode for all *.org files
+
  
;; Some key sequences
+
* Create the directory <tt>lib/python/example</tt>.
(define-key global-map "\C-cl" 'org-store-link)
+
* Create the file <tt>lib/python/example/__init__.py</tt> by typing <tt>touch lib/python/example/__init__.py</tt>.
(define-key global-map "\C-ca" 'org-agenda)
+
* Create these files:
(global-set-key [f9]    'org-archive-subtree-default)
+
  
(setq org-log-done t) ;; I have no idea what this does, it was in the manual -- think it controls whether or not to log time completed for tasks
+
=== <tt>etc/package-includes/example-configure.zcml</tt> ===
  
(setq org-directory "~/notes")
+
This file registers the ''<tt>example</tt>'' directory you created in ''<tt>lib/python</tt>'' as a ''package'', so that it is seen by Zope:
  
;; Files that should be included in agenda views:
+
<console>
(setq org-agenda-files (list "~/notes/business.org"
+
<include package="example" />
                            "~/notes/personal.org"
+
</console>
                            "~/notes/projects/"
+
    "~/notes/projects/writing/"))
+
  
(setq org-todo-keywords '((type "TODO" "Postponed" "Upcoming" "Doing" "|" "DONE(#)"))) ;; TODO workflows
+
=== <tt>lib/python/example/interfaces.py</tt> ===
  
(setq org-tag-alist '(("work" . ?k) ("personal" . ?p) ("organization" . ?o) ("writing" . ?w) ("code" . ?c) ("blog" . ?b) ("funtoo" . ?f) ("social" . ?s))) ;; Most-used tags, with shortcuts
+
The following file defines the ''<tt>ITODO</tt>'' interface, and also uses some Zope Schema functions to define what kind of data we expect to store in objects that implement ''<tt>ITODO</tt>'':
  
;; Capture stuff
+
<console>
(setq org-default-notes-file "~/.org/capture.org")
+
from zope.interface import Interface
(define-key global-map "\C-cc" 'org-capture)
+
from zope.schema import List, Text, TextLine, Int
(setq org-refile-targets '((org-agenda-files :level . 1)(org-agenda-files :level . 2)))
+
(setq org-refile-use-outline-path 'file)
+
  
(setq org-capture-templates
+
class ITODO(Interface):
      '(("t" "Todo" entry (file+headline "~/.org/capture.org" "Tasks")
+
    name = TextLine(title=u'Name', required=True)
            "- TODO %?\n  %i\n  %a")
+
    todo = List(title=u"TODO Items", required=True, value_type=TextLine(title=u'TODO'))
        ("j" "Journal" entry (file+datetree "~/.org/journal.org")
+
    daysleft = Int(title=u'Days left to complete', required=True)
            "- %?\nEntered on %U\n  %i\n  %a")))
+
    description = Text(title=u'Description', required=True)
 +
</console>
  
(setq org-mobile-directory "~/Dropbox/MobileOrg")
+
=== <tt>lib/python/example/TODO.py</tt> ===
(setq org-mobile-use-encryption)
+
(setq org-mobile-use-encryption-password "PASSWORD")
+
(setq org-mobile-inbox-for-pull "~/notes/mobileorg/inbox.org")
+
  
;;;;;;;;;;;;;;;;;;;
+
Now, we define ''<tt>TODO</tt>'' to be a ''persistent'' object, meaning it can be stored in the ZODB. We specify that it implements our previously-defined ''<tt>ITODO</tt>'' interface, and provide reasonable defaults for all values when we create a new TODO object:
;; Markdown Mode ;;
+
<console>
;;;;;;;;;;;;;;;;;;;
+
from persistent import Persistent
 +
from zope.interface import implements
 +
from example.interfaces import ITODO
  
(require 'markdown-mode)
+
class TODO(Persistent):
(add-to-list 'auto-mode-alist '("\\.markdown$" . markdown-mode))
+
    implements(ITODO)
(add-to-list 'auto-mode-alist '("\\.md$" . markdown-mode))
+
    name = u''
 +
    todo = []
 +
    daysleft = 0
 +
    description = u''
 +
</console>
  
;;;;;;;;;;;;;;;;
+
=== <tt>lib/python/example/configure.zcml</tt> ===
;; Python IDE ;;
+
;;;;;;;;;;;;;;;;
+
(c-add-style
+
  "python-new"
+
  '((indent-tabs-mode . nil)
+
    (fill-column      . 78)
+
    (c-basic-offset  . 4)
+
    (c-offsets-alist  . ((substatement-open . 0)
+
                          (inextern-lang    . 0)
+
                          (arglist-intro    . +)
+
                          (knr-argdecl-intro . +)))
+
    (c-hanging-braces-alist . ((brace-list-open)
+
                                (brace-list-intro)
+
                                (brace-list-close)
+
                                (brace-entry-open)
+
                                (substatement-open after)
+
                                (block-close . c-snug-do-while)))
+
    (c-block-comment-prefix . "* "))
+
)
+
  
;; This is a very crude hook that auto-selects the C style depending on
+
Create an empty ''<tt>configure.zcml</tt>'' configuration file:
;; whether it finds a line starting with tab in the first 3000 characters
+
<console>
;; in the file
+
<configure xmlns="http://namespaces.zope.org/zope"
(defun c-select-style ()
+
    xmlns:five="http://namespaces.zope.org/five"
  (save-excursion
+
    xmlns:browser="http://namespaces.zope.org/browser">
    (if (re-search-forward "^\t" 3000 t)
+
</configure>
        (c-set-style "python")
+
</console>
      (c-set-style "python-new"))))
+
(add-hook 'c-mode-hook 'c-select-style)
+
  
;;;;;;;;;;;;
+
== Debug Mode ==
;; Django ;;
+
;;;;;;;;;;;;
+
(yas/initialize)
+
(add-to-list 'load-path "~/.emacs.d/el-get/django-mode/")
+
(require 'django-html-mode)
+
(require 'django-mode)
+
(yas/load-directory "~/.emacs.d/el-get/django-mode/snippets")
+
(add-to-list 'auto-mode-alist '("\\.djhtml$" . django-html-mode))
+
  
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
We can test our first project by entering debug mode:
;; Document Engineering (AUCTeX + ConTeXt) ;;
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
(load "auctex.el" nil t t)
+
(load "preview-latex.el" nil t t)
+
 
+
(setq TeX-auto-save 1)
+
(setq TeX-parse-self 1)
+
(setq TeX-auto-untabify 1)
+
(setq TeX-display-help 1)
+
(setq TeX-save-query nil)
+
(setq TeX-clean-confirm nil)
+
(setq-default TeX-master nil)
+
 
+
(add-hook 'TeX-mode-hook (lambda () (TeX-fold-mode 1)))
+
(add-hook 'TeX-mode-hook (lambda () (TeX-source-specials-mode 1)))
+
(add-hook 'TeX-mode-hook (lambda () (TeX-toggle-debug-bad-boxes)))
+
(add-hook 'TeX-mode-hook (lambda () (TeX-toggle-debug-warnings)))
+
(add-hook 'TeX-mode-hook (lambda () (outline-minor-mode)))
+
(add-hook 'TeX-mode-hook (lambda () (abbrev-mode t)))
+
(add-hook 'TeX-mode-hook (lambda () (auto-fill-mode 1)))
+
 
+
(add-hook 'TeX-mode-hook 'LaTeX-math-mode)
+
 
+
(autoload 'etexshow "etexshow" "Browser for ConTeXt commands." t)
+
 
+
(setq etexshow-xml-files-alist
+
  `((,(concat emacs-root-dir "libs/etexshow/cont-en.xml") .
+
      ,(concat "/tmp/cont-en.cache"))))
+
 
+
(setq etexshow-comment-file
+
  (concat emacs-root-dir "libs/etexshow/cont-en-comments.xml"))
+
 
+
(setq TeX-PDF-mode 1)
+
(setq revert-without-query '(".+pdf$"))
+
(add-hook 'doc-view-mode-hook 'auto-revert-mode)
+
 
+
;;;;;;;;;;
+
;; bbdb ;;
+
;;;;;;;;;;
+
(setq bbdb-file "~/.emacs.d/.bbdb")
+
(require 'bbdb)
+
(bbdb-initialize)
+
(setq
+
bbdb-offer-save 1                        ;; 1 means save-without-asking
+
bbdb-use-pop-up t                        ;; allow popups for addresses
+
bbdb-electric-p t                        ;; be disposable with SPC
+
bbdb-popup-target-lines 1                ;; very small
+
bbdb-dwim-net-address-allow-redundancy t  ;; always use full name
+
bbdb-quiet-about-name-mismatches 2        ;; show name-mismatches 2 secs
+
bbdb-always-add-address t                ;; add new addresses to existing...
+
                                          ;; ...contacts automatically
+
bbdb-canonicalize-redundant-nets-p t      ;; x@foo.bar.cx => x@bar.cx
+
bbdb-completion-type nil                  ;; complete on anything
+
bbdb-complete-name-allow-cycling t        ;; cycle through matches
+
                                          ;; this only works partially
+
bbdb-message-caching-enabled t            ;; be fast
+
bbdb-use-alternate-names t                ;; use AKA
+
bbdb-elided-display t                    ;; single-line addresses
+
;; auto-create addresses from mail
+
bbdb/mail-auto-create-p 'bbdb-ignore-some-messages-hook
+
bbdb-ignore-some-messages-alist          ;; don't ask about fake addresses
+
;; NOTE: there can be only one entry per header (such as To, From)
+
;; http://flex.ee.uec.ac.jp/texi/bbdb/bbdb_11.html
+
'(( "From" . "no.?reply\\|DAEMON\\|daemon\\|facebookmail\\|twitter")))
+
 
+
;;;;;;;;;;;;;;;;;
+
;; Jabber Mode ;;
+
;;;;;;;;;;;;;;;;;
+
 
+
(require 'jabber-autoloads)
+
(setq jabber-account-list '(
+
                            ("USER@jabber-server.tld"
+
                            (:password . "PASSWORD")
+
                            )
+
                          )
+
)
+
(setq
+
    jabber-history-enabled t
+
    jabber-use-global-history nil
+
    jabber-backlog-number 40
+
    jabber-backlog-days 30
+
)
+
 
+
(add-hook 'jabber-chat-mode-hook 'goto-address)
+
 
+
(load "~/.emacs.d/plugins/autosmiley.el")
+
(require 'autosmiley)
+
(add-hook 'jabber-chat-mode-hook 'autosmiley-mode)
+
 
+
(defvar libnotify-program "/usr/bin/notify-send")
+
 
+
(defun notify-send (title message)
+
  (start-process "notify" " notify"
+
                libnotify-program "--expire-time=4000" title message))
+
 
+
(defun libnotify-jabber-notify (from buf text proposed-alert)
+
  "(jabber.el hook) Notify of new Jabber chat messages via libnotify"
+
  (when (or jabber-message-alert-same-buffer
+
                        (not (memq (selected-window) (get-buffer-window-list buf))))
+
    (if (jabber-muc-sender-p from)
+
        (notify-send (format "(PM) %s"
+
                            (jabber-jid-displayname (jabber-jid-user from)))
+
                    (format "%s: %s" (jabber-jid-resource from) text)))
+
    (notify-send (format "%s" (jabber-jid-displayname from))
+
                text)))
+
 
+
(add-hook 'jabber-alert-message-hooks 'libnotify-jabber-notify)
+
 
+
(defun jabber-visit-history (jid)
+
  "Visit jabber history with JID in a new buffer.
+
 
+
Performs well only for small files. Expect to wait a few seconds
+
for large histories. Adapted from `jabber-chat-create-buffer'."
+
  (interactive (list (jabber-read-jid-completing "JID: ")))
+
  (let ((buffer (generate-new-buffer (format "*-jabber-history-%s-*"
+
                                            (jabber-jid-displayname jid)))))
+
    (switch-to-buffer buffer)
+
    (make-local-variable 'jabber-chat-ewoc)
+
    (setq jabber-chat-ewoc (ewoc-create #'jabber-chat-pp))
+
    (mapc 'jabber-chat-insert-backlog-entry
+
          (nreverse (jabber-history-query nil nil t t "."
+
                                          (jabber-history-filename jid))))
+
    (view-mode)))
+
 
+
;;;;;;;;;;
+
;; EMMS ;;
+
;;;;;;;;;;
+
(require 'emms-setup)
+
(emms-devel)
+
(emms-default-players)
+
 
+
;;;;;;;;;
+
;; ERC ;;
+
;;;;;;;;;
+
(require 'erc)
+
(require 'erc-extension)
+
(require 'erc-services)
+
(require 'erc-tex)
+
(require 'tls)
+
(require 'erc-nicklist)
+
 
+
(and
+
(require 'erc-highlight-nicknames)
+
(add-to-list 'erc-modules 'highlight-nicknames)
+
(erc-update-modules))
+
 
+
(erc-services-mode 1)
+
 
+
(setq tls-program '("openssl s_client -connect %h:%p -no_ssl2 -ign_eof
+
                            -CAfile /home/USER/.ssl/USER.pem
+
                            -cert /home/USER/.ssl/USER.pem"
+
                    "gnutls-cli --priority secure256
+
                                --x509cafile /home/USER/.ssl/USER.pem
+
                                --x509certfile /home/USER/.ssl/USER.pem -p %p %h"
+
                    "gnutls-cli --priority secure256 -p %p %h"))
+
 
+
(autoload 'erc-nick-notify-mode "erc-nick-notify" "Minor mode that calls `erc-nick-notify-cmd' when his nick gets mentioned in an erc channel" t)
+
(eval-after-load 'erc '(erc-nick-notify-mode t))
+
(defun irc-erc ()
+
  "Fire up IRC."
+
  (interactive)
+
  (erc-tls :server "chat.freenode.net" :port 7000 :nick "USER" :full-name "FULL NAME" :password "PASSWORD"))
+
 
+
(setq erc-autojoin-channels-alist '(("freenode.net" "#frogandowl" "#funtoo" "#funtoo-quebec" "#syntazia" "#context" "#nginx" "#emacs" "#openvswitch")))
+
(setq erc-log-channels-directory "~/.erc/logs/")
+
(setq erc-log-insert-log-on-open nil)
+
(setq erc-save-buffer-on-part nil
+
      erc-save-buffer-queries-on-quit nil
+
      erc-log-write-after-send t
+
      erc-log-write-after-insert t)
+
 
+
(require 'smiley)
+
    (add-to-list 'smiley-regexp-alist '("\\(:-?]\\)\\W" 1 "forced"))
+
    (add-to-list 'smiley-regexp-alist '("\\s-\\(:-?/\\)\\W" 1 "wry"))
+
    (add-to-list 'smiley-regexp-alist '("\\(:-?(\\)\\W" 1 "sad"))
+
    (add-to-list 'smiley-regexp-alist '("\\((-?:\\)\\W" 1 "reverse-smile"))
+
    (add-to-list 'smiley-regexp-alist '("\\(:-?D\\)\\W" 1 "grin"))
+
    (add-to-list 'smiley-regexp-alist '("\\(:-?P\\)\\W" 1 "poke"))
+
 
+
;; (setq smiley-cached-regexp-alist nil)
+
;; (smiley-update-cache)
+
 
+
;;;;;;;;;;;;;;;;
+
;; Wanderlust ;;
+
;;;;;;;;;;;;;;;;
+
(autoload 'wl "wl" "Wanderlust" t)
+
 
+
;;;;;;;;;;;;;;;
+
;; mailcrypt ;;
+
;;;;;;;;;;;;;;;
+
(require 'mailcrypt)
+
(add-hook 'wl-summary-mode-hook 'mc-install-read-mode)
+
(add-hook 'wl-mail-setup-hook 'mc-install-write-mode)
+
 
+
(defun mc-wl-verify-signature ()
+
  (interactive)
+
  (save-window-excursion
+
    (wl-summary-jump-to-current-message)
+
    (mc-verify)))
+
 
+
(defun mc-wl-decrypt-message ()
+
  (interactive)
+
  (save-window-excursion
+
    (wl-summary-jump-to-current-message)
+
    (let ((inhibit-read-only t))
+
      (mc-decrypt))))
+
 
+
(eval-after-load "mailcrypt"
+
  '(setq mc-modes-alist
+
        (append
+
          (quote
+
          ((wl-draft-mode (encrypt . mc-encrypt-message)
+
                          (sign . mc-sign-message))
+
            (wl-summary-mode (decrypt . mc-wl-decrypt-message)
+
                            (verify . mc-wl-verify-signature))))
+
          mc-modes-alist)))
+
 
+
;;;;;;;;;;;;;;;;;;;;;
+
;; notify function ;;
+
;;;;;;;;;;;;;;;;;;;;;
+
(defun djcb-popup (title msg &optional icon sound)
+
  "Show a popup if we're on X, or echo it otherwise; TITLE is the title of the message, MSG is the context. Optionally, you can provide an ICON and a sound to be played"
+
  (interactive)
+
  (when sound (shell-command
+
              (concat "mplayer2 -really-quiet " sound " 2> /dev/null")))
+
  (if (eq window-system 'x)
+
      (shell-command (concat "notify-send "
+
                           
+
                            (if icon (concat "-i " icon) "")
+
                            " '" title "' '" msg "'"))
+
    ;; text only version
+
    (message (concat title ": " msg))))
+
 
+
;; the appointment notification facility
+
(setq
+
appt-message-warning-time 15 ;; warn 15 min in advance
+
appt-display-mode-line t    ;; show in the modeline
+
appt-display-format 'window) ;; usr our func
+
(appt-activate t)            ;; active appt (appointment notification)
+
(display-time)
+
 
+
;; update appt each time agenda opened
+
(add-hook 'org-finalize-agenda-hook 'org-agenda-to-appt)
+
 
+
;; our little facade-function for djcb-popup
+
(defun djcb-appt-display (min-to-app new-time msg)
+
  (djcb-popup (format "Appointment in %s minute(s)" min-to-app) msg
+
              "/usr/share/icons/gnome/32x32/status/appointment-soon.png"
+
              "/usr/share/sounds/purple/alert.wav"))
+
(setq appt-disp-window-function (function djcb-appt-display))
+
 
+
;;;;;;;;;;;;;;;;;;;;;;;;;;
+
;; Custom Variable sets ;;
+
;;;;;;;;;;;;;;;;;;;;;;;;;;
+
(custom-set-variables
+
  ;; custom-set-variables was added by Custom.
+
  ;; If you edit it by hand, you could mess it up, so be careful.
+
  ;; Your init file should contain only one such instance.
+
  ;; If there is more than one, they won't work right.
+
'(TeX-command-list (quote (("TeX" "%(PDF)%(tex) %`%S%(PDFout)%(mode)%' %t" TeX-run-TeX nil (plain-tex-mode texinfo-mode ams-tex-mode) :help "Run plain TeX") ("LaTeX" "%`%l%(mode)%' %t" TeX-run-TeX nil (latex-mode doctex-mode) :help "Run LaTeX") ("Makeinfo" "makeinfo %t" TeX-run-compile nil (texinfo-mode) :help "Run Makeinfo with Info output") ("Makeinfo HTML" "makeinfo --html %t" TeX-run-compile nil (texinfo-mode) :help "Run Makeinfo with HTML output") ("AmSTeX" "%(PDF)amstex %`%S%(PDFout)%(mode)%' %t" TeX-run-TeX nil (ams-tex-mode) :help "Run AMSTeX") ("ConTeXt MKIV" "context %t" TeX-run-TeX nil (context-mode) :help "Run ConTeXt MKIV") ("ConTeXt" "texexec --once --texutil %(execopts)%t" TeX-run-TeX nil (context-mode) :help "Run ConTeXt once") ("ConTeXt Full" "texexec %(execopts)%t" TeX-run-TeX nil (context-mode) :help "Run ConTeXt until completion") ("BibTeX" "bibtex %s" TeX-run-BibTeX nil t :help "Run BibTeX") ("View" "%V" TeX-run-discard-or-function t t :help "Run Viewer") ("Print" "%p" TeX-run-command t t :help "Print the file") ("Queue" "%q" TeX-run-background nil t :help "View the printer queue" :visible TeX-queue-command) ("File" "%(o?)dvips %d -o %f " TeX-run-command t t :help "Generate PostScript file") ("Index" "makeindex %s" TeX-run-command nil t :help "Create index file") ("Check" "lacheck %s" TeX-run-compile nil (latex-mode) :help "Check LaTeX file for correctness") ("Spell" "(TeX-ispell-document \"\")" TeX-run-function nil t :help "Spell-check the document") ("Clean" "TeX-clean" TeX-run-function nil t :help "Delete generated intermediate files") ("Clean All" "(TeX-clean t)" TeX-run-function nil t :help "Delete generated intermediate and output files") ("Other" "" TeX-run-command t t :help "Run an arbitrary command"))))
+
'(column-number-mode t)
+
'(erc-modules (quote (autojoin bbdb button completion fill irccontrols list log match menu move-to-prompt netsplit networks noncommands readonly ring services smiley stamp spelling track)))
+
'(mediawiki-site-alist (quote (("Funtoo" "http://www.funtoo.org/" "USER" "PASSWORD" "")))))
+
(custom-set-faces
+
  ;; custom-set-faces was added by Custom.
+
  ;; If you edit it by hand, you could mess it up, so be careful.
+
  ;; Your init file should contain only one such instance.
+
  ;; If there is more than one, they won't work right.
+
)
+
 
+
;;;;;;;;;;;;;;;;;;
+
;; Color-Themes ;;
+
;;;;;;;;;;;;;;;;;;
+
;;(add-to-list 'load-path "/usr/share/emacs/site-lisp/color-theme/color-theme.el")
+
;;(add-to-list 'load-path "~/.emacs.d/themes/")
+
(require 'color-theme)
+
(color-theme-initialize)
+
;;(color-theme-subtle-hacker)
+
(color-theme-twilight)
+
;;(eval-after-load "color-theme"
+
;;  '(progn
+
;;    (color-theme-initialize)
+
;;    (require 'color-theme-citrus)
+
;;    (require 'color-theme-candy)
+
;;    (require 'color-theme-autumn-leaves)
+
;;    (require 'color-theme-inthedark)
+
;;    (require 'color-theme-marine)
+
;;    (require 'color-theme-october)
+
;;    (require 'color-theme-eatyourgreens)
+
;;    (require 'color-theme-august)
+
;;    (require 'color-theme-saddle-2)
+
;;    (color-theme-saddle-2)))
+
;;    (color-theme-subtle-hacker)))
+
 
+
(setq css-indent-offset 2)
+
</console>
+
 
+
==== .wl ====
+
 
<console>
 
<console>
###i## nano ~/.wl
+
$##bl## bin/zopectl debug
;; load bbdb support
+
Starting debugger (the name "app" is bound to the top-level Zope object)
(require 'bbdb-wl)
+
(bbdb-wl-setup)
+
 
+
;; setup from where to get addresses
+
(setq bbdb-wl-folder-regexp "^\.INBOX|^\.inbox|^\.Sent|^\.sent|^\.\[IMAPS\]\\Sent")
+
 
+
;; define keybinding
+
(define-key wl-draft-mode-map (kbd "<C-tab>") 'bbdb-complete-name)
+
 
+
;; set multiple e-mail addresses
+
(setq wl-user-mail-address-list (quote ("User@googlemail.com" "USER@own-server.tld")))
+
 
+
;; handle ("d") mark
+
;; remove = instant removal (same as "D"), thrash = move to wl-trash-folder
+
;; string = move to string
+
(setq wl-dispose-folder-alist
+
      '(
+
        ("\.\*googlemail\\.com" "%[Imap]/Trash:"User@googlemail.com"/clear@imap.gmail.com:993!")
+
        ("\.\*@own\-\server\\.tld" "%INBOX.Trash:"USER"/clear@imap.own-server.tld")
+
))
+
 
+
;; notify hook
+
(add-hook 'wl-biff-notify-hook
+
          (lambda()
+
            (djcb-popup "Wanderlust" "You have new mail!"
+
                        "/usr/share/icons/gnome/32x32/status/mail-unread.png"
+
                        "/usr/share/sounds/purple/alert.wav")))
+
 
+
;; timer settings
+
(setq
+
wl-biff-check-interval 30 ;; check every 30 seconds
+
wl-biff-use-idle-timer t) ;; in the background
+
 
+
;; Name of top-folder, default "Desktop"
+
(setq wl-folder-desktop-name "e-Mail")
+
 
+
;; select correct email address when we _start_ writing a draft.
+
(add-hook 'wl-mail-setup-hook 'wl-draft-config-exec)
+
 
+
(setq wl-draft-config-alist
+
      '(
+
        ((string-match "googlemail.com" wl-draft-parent-folder)
+
        (template . "User"))
+
        ((string-match "own-server.tld" wl-draft-parent-folder)
+
        (template . "USER"))
+
))
+
 
+
;; choose template with C-c C-j
+
(setq wl-template-alist
+
      '(("User"
+
        (wl-from . "Full Name <User@googlemail.com>")
+
        ("From" . wl-from)
+
        (wl-smtp-posting-user . "User")
+
        (wl-smtp-posting-server . "smtp.gmail.com")
+
        (wl-smtp-authenticate-type . "plain")
+
        (wl-smtp-connection-type . 'starttls)
+
        (wl-smtp-posting-port . 587)
+
        (wl-local-domain . "googlemail.com")
+
        (wl-message-id-domain . "smtp.gmail.com")
+
       
+
        (wl-fcc .  "%[IMAPS]/Sent:\"User@googlemail.com\"/clear@imap.gmail.com:993!")
+
        (wl-draft-folder .  "%[IMAPS]/Draft:\"User@googlemail.com\"/clear@imap.gmail.com:993!")
+
        )
+
        ("USER"
+
        (wl-from  . "Full Name <USER@own-server.tld>")
+
        ("From"  . wl-from)
+
        (wl-smtp-posting-user  . "USER")
+
        (wl-smtp-posting-server  . "smtp.own-server.tld")
+
        (wl-local-domain . "own-server.tld")
+
       
+
        (wl-fcc  "%INBOX.Sent:USER/digest-md5@imap.own-server.tld:143")
+
        (wl-draft-folder  "%INBOX.Drafts:USER/digest-md5@imap.own-server.tld:143")
+
        )
+
      )
+
)
+
 
+
(define-key wl-template-mode-map (kbd "<right>") 'wl-template-next)
+
(define-key wl-template-mode-map (kbd "<left>") 'wl-template-prev)
+
 
+
(setq wl-default-spec "%")
+
 
+
(setq wl-fcc-force-as-read t)
+
(setq wl-auto-save-drafts-interval nil)
+
 
</console>
 
</console>
  
==== .folders ====
+
Now, let's try creating a new TODO object and writing it out to a ZODB database:
 
<console>
 
<console>
###i## nano ~/.folders
+
>>> from ZODB import FileStorage, DB
User@googlemail{
+
>>> storage = FileStorage.FileStorage('mydatabase.fs')
        %INBOX:"User@googlemail.com"/clear@imap.gmail.com:993!    "Inbox"
+
>>> db = DB(storage)
        [IMAPS-gmail]{
+
>>> connection = db.open()
                %[IMAPS]/Sent:"User@googlemail.com"/clear@imap.gmail.com:993!      "Sent"
+
>>> import transaction
                %[IMAPS]/Draft:"User@googlemail.com"/clear@imap.gmail.com:993!      "Draft"
+
>>> root = connection.root()
                %[IMAPS]/Spam:"User@googlemail.com"/clear@imap.gmail.com:993!      "Spam"
+
>>> from example.TODO import TODO
                %[IMAPS]/Trash:"User@googlemail.com"/clear@imap.gmail.com:993!      "Trash"
+
>>> a = TODO
        }
+
>>> a.name = u'My TODOs'
}
+
>>> a.TODOS = [ u'Do Laundry', u'Wash Dishes' ]
USER@own-server.tld{
+
>>> a.daysleft = 1
        %INBOX:USER/digest-md5@imap.own-server.tld  "Inbox"
+
>>> a.description = u'Things I need to do today.'
        %INBOX.Sent:USER/digest-md5@imap.own-server.tld "Sent"
+
>>> root[u'today'] = a
        %INBOX.Drafts:USER/digest-md5@imap.own-server.tld "Drafts"
+
>>> transaction.commit()
}
+
 
</console>
 
</console>
  
 
[[Category:HOWTO]]
 
[[Category:HOWTO]]
 
[[Category:Featured]]
 
[[Category:Featured]]

Revision as of 14:21, 13 January 2014

This page documents how to use Zope with Funtoo Experimental, which currently has good Zope support thanks to Progress Overlay Python integration.

Contents

About Zope

Zope is an Open Source application server framework written in Python. It has an interesting history which you should familiarize yourself with before starting Zope development, as it contains several interesting twists and turns.

Zope History

Note Note: This HOWTO targets Zope 2.13, which includes Five. It is typically the version you should be using for new Zope projects.

  • There are two versions of Zope, Zope 2 and Zope 3. One might assume that Zope 3 is the version that people should use for new software development projects by default, but this is not the case. Most Zope-based projects continue to use Zope 2. Zope 3 was an attempt to redesign Zope 2 from scratch, and is completely different from Zope 2, but it was not adopted by the community.
  • There is also something called Five (named because it is "2 + 3") that backports many of the new features of Zope 3 into the Zope 2 framework. Several projects will use Zope 2 plus Five in order to use some of the newer features in Zope. Five was merged into mainline Zope 2 in early 2010, and first appeared in Zope 2.8.
  • You can learn more about the history of Zope 2, 3 and Five in the Five README.
  • To make things even more interesting, work on Zope 4 is underway, and it will be based on 2.13 rather than 3.x. It includes a number of incompatible changes with prior versions.

Zope Resources

Now that you understand what version of Zope you should be targeting (2.13), we can point you towards the correct documentation :)

The Zope 2 Book
This book provides a general introduction to Zope concepts and ZMI. It is a good place to start, but doesn't provide a direct introduction to Zope development. It's recommended that you skim through this book to familiarize yourself with Zope. It generally does not assume much prior knowledge about Web development or Python.
Zope Developer's Guide
This guide will give you a better introduction to Zope development. It assumes you already know Python. Skip chapters 1 and 2 and start in chapter 3, which covers components and interfaces. Chapter 5 covers the creation of your first product.
Five
We're not done yet. There is a bunch of stuff in Zope 2.13 that is not in the official documentation. Namely, the stuff in Five. Check out The Five Manual.
ZTK
ZTK Documentation
ZCA
A Comprehensive Guide to Zope Component Architecture offers a good introduction to the programming concepts of ZCA. We also have a new page on Zope Component Architecture which will help you to understand the big picture of ZCA and why it is useful. ZCML ("Z-camel") is a part of ZCA and was introduced in Zope 3, so typically you will find ZCML documented within Zope 3 documentation and book.
Content Components
Views and Viewlets: This tutorial on viewlets also contains some viewlet-related ZCML examples near the end. The "Content Component way" of developing in Zope seems to be a Zope 3 thing and tied to ZCML. Chapter 13+ of Stephan Richter's Zope 3 Developer's Handbook (book) seems to cover this quite well. You will probably also want to check out Philipp Weitershausen's Web Component Development with Zope 3 (book).
Zope 2 Wiki
Main wiki page for all things related to Zope 2.
docs.zope.org
This is the main site for Zope documentation.

First Steps

First, you will need to emerge net-zope/zope:

#  emerge -av zope

Zope is now installed.

Project Skeleton

Note Note: Zope should be run by a regular user account, not as the root user.

The first step in using Zope is to ensure that you are using a regular user account. Create a new directory called zope_test:

$ cd
$ mkdir zope_test

Now, enter the directory, and create an "instance", which is a set of files and directories that are used to contain a Zope project:

$ cd zope_test
$ /usr/lib/zope-2.13/bin/mkzopeinstance

You will see the following output, and will be prompted to answer a few questions:

Please choose a directory in which you'd like to install
Zope "instance home" files such as database files, configuration
files, etc.

Directory: instance
Please choose a username and password for the initial user.
These will be the credentials you use to initially manage
your new Zope instance.

Username: admin
Password: ****
Verify password: **** 

Now, we will start our Zope instance:

$ cd instance
$ bin/runzope

Now that Zope is running, you can visit localhost:8080 in your Web browser. You will see a nice introductory page to Zope.

If you now go to the localhost:8080/manage URL, you will be prompted to log in. Enter the username and password you specified. You are now logged in to the ZMI (Zope Management Interface.)

You can stop your application by pressing Control-C. In the future, you can start and stop your Zope instance using the following commands:

$ zopectl start
$ zopectl stop

Note Note: zopectl start will cause your instance to run in the background rather than consuming a shell console.

First Project

We will create a single very primitive Zope package, consisting of an Interface for a TODO class, and a TODO class.

Create the following files and directories relative to your project root:

  • Create the directory lib/python/example.
  • Create the file lib/python/example/__init__.py by typing touch lib/python/example/__init__.py.
  • Create these files:

etc/package-includes/example-configure.zcml

This file registers the example directory you created in lib/python as a package, so that it is seen by Zope:

<include package="example" />

lib/python/example/interfaces.py

The following file defines the ITODO interface, and also uses some Zope Schema functions to define what kind of data we expect to store in objects that implement ITODO:

from zope.interface import Interface
from zope.schema import List, Text, TextLine, Int

class ITODO(Interface):
    name = TextLine(title=u'Name', required=True)
    todo = List(title=u"TODO Items", required=True, value_type=TextLine(title=u'TODO'))
    daysleft = Int(title=u'Days left to complete', required=True)
    description = Text(title=u'Description', required=True)

lib/python/example/TODO.py

Now, we define TODO to be a persistent object, meaning it can be stored in the ZODB. We specify that it implements our previously-defined ITODO interface, and provide reasonable defaults for all values when we create a new TODO object:

from persistent import Persistent
from zope.interface import implements
from example.interfaces import ITODO

class TODO(Persistent):
    implements(ITODO)
    name = u''
    todo = []
    daysleft = 0
    description = u''

lib/python/example/configure.zcml

Create an empty configure.zcml configuration file:

<configure xmlns="http://namespaces.zope.org/zope"
     xmlns:five="http://namespaces.zope.org/five"
     xmlns:browser="http://namespaces.zope.org/browser">
</configure>

Debug Mode

We can test our first project by entering debug mode:

$ bin/zopectl debug
Starting debugger (the name "app" is bound to the top-level Zope object)

Now, let's try creating a new TODO object and writing it out to a ZODB database:

>>> from ZODB import FileStorage, DB
>>> storage = FileStorage.FileStorage('mydatabase.fs')
>>> db = DB(storage)
>>> connection = db.open()
>>> import transaction
>>> root = connection.root()
>>> from example.TODO import TODO
>>> a = TODO
>>> a.name = u'My TODOs'
>>> a.TODOS = [ u'Do Laundry', u'Wash Dishes' ]
>>> a.daysleft = 1
>>> a.description = u'Things I need to do today.'
>>> root[u'today'] = a
>>> transaction.commit()